views:

340

answers:

1

I'm making WCF calls from a Mono client running on Ubuntu (Mono 2.6).

I can't seem to add a custom header to my messages. I have tried two different ways:

  • Using a [MessageContract] and [MessageHeader] attributes on a custom class
  • Adding the header to the outgoing messages programmatically, e.g.

    MessageHeader mhg = new MessageHeader("test");
    MessageHeader untyped = mhg.GetUntypedHeader("token", "ns");
    OperationContext.Current.OutgoingMessageHeaders.Add(untyped);

The header is not there when the call reaches the server! It's always null.

Note that both methods work fine running on .NET in Windows. Also note that the message body gets through just fine on Mono.

I see some references online that suggest this should work:

http://forums.monotouch.net/yaf_postsm1692.aspx
https://bugzilla.novell.com/show_bug.cgi?id=551745

Also - the Mono status page shows that all the MessageHeader stuff is fully implemented...

Anyone had luck with this?

Thanks in advance, Richard

+1  A: 

I'm struggling with similar issues.

I've solved the problem with a C# client and server. Assuming you've got the client side right, my experience might help:

My service method looks like this:

public FileUploadResult UploadFileSegment(FileUploadMessage uploadMessage)

And my service method parameter class looks like this:

 [MessageContract]
  public class FileUploadMessage
  {
    [MessageHeader(MustUnderstand = false, Name="Metadata", Namespace = "")]
    public FileUploadMetadata Metadata;

    [MessageBodyMember(Order = 1)]
    public Stream FileByteStream { get; set; }
  }

Note the Name= and Namespace= assignments within the attribute.

When I inject the message headers on the client side, I also specify the name and namespace . In C# it looks like this:

using (OperationContextScope contextScope = new OperationContextScope(proxy.InnerChannel))
  {
    OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("Metadata", "", uploadHeader));
    proxy.UploadFileSegmentAsync(uploadMessage);
  }

The result is that the named custom header I provide in the client is mapped to the similarly named (via attribute) property on the method parameter instance.

Trevor
This solved the problem for me. My MessageHeaders are now getting through properly! I had to actually include a namespace rather than just an empty string - .NET didn't mind, but Mono threw an exception with the empty namespace. I will file it as a bug when I get chance. Thanks for your help!
TheNextman
OK I think I spoke to soon. I realized that since I posted this question, I updated my Mono install to the trunk version (2.7). When I go back and test this on 2.6.4, it doesn't work. So it seems that this bug has been fixed but not yet made it into a release. What version of Mono are you on?
TheNextman
I'm not: I'm calling from a Windows client. Can't help out with Mono I'm afraid.
Trevor