0

Essentially I'm trying to send an object of the following type to a WCF service from SilverLight. The message contract of the object is the following:

[MessageContract]
    public class UploadMessage
    {
        [MessageHeader(MustUnderstand = true)]
        public Token Token;

        [MessageHeader(MustUnderstand = true)]
        public string FileExtension;

        [MessageHeader(MustUnderstand = true)]
        public Product Product;

        [MessageBodyMember(Order = 1)]
        public Stream FileByteStream;

}

[OperationContract(IsOneWay = true)]
        void UploadFileStream(UploadMessage upm);

However whenever I try to call the method from the SilverLight client I can only specify the FileByteStream parameter (not the other 3).

What could possibly be the issue here?

John Mayer
  • 3,313
  • 3
  • 19
  • 20
  • Maybe because they're in Header? In any case, if you write the code of your client it would be much easier to help you :) – Rafa Apr 15 '13 at 13:02
  • Well how can I include the header on the client side then? And the client code is not really essential here since it's just a call to the web service in which it apparently only accepts 1 parameter (the byte array) and not any of the headers – John Mayer Apr 15 '13 at 13:06
  • The header is always there, every HTTP message has a Header and a Body, and usually WCF (or WebAPI or whatever you're using to write the client) offers functions to access the Header in the response and in the request objects... The code would help. – Rafa Apr 15 '13 at 13:08
  • If you really want to see then code where I call the webservice then sure, here it is: `code` var memoryStream = new MemoryStream(); ofd.File.OpenRead().CopyTo(memoryStream); byte[] bytes = memoryStream.ToArray(); UploadMessage msg = new UploadMessage(); service.UploadFileStreamAsync(bytes); - doesn't accept any more parameters `code` Although I don't see the use of it. – John Mayer Apr 15 '13 at 13:11
  • OK, this is the memory stream that comes from the wire, but there is no message contract defined there, only raw data. The answer from Nabheet will help you, I think your client is not properly implemented. – Rafa Apr 15 '13 at 13:27
  • I could be wrong, but I don't think Silverlight supports MessageHeader. Here is another question on this topic, with a suggested workaround: http://stackoverflow.com/questions/13942113/silverlight-is-not-liking-my-wcf-messagecontract-why – Henrik Söderlund Apr 16 '13 at 14:00

1 Answers1

1

Are you using Visual Studio?

Did you update the service reference to your WCF service in the Silverlight project after adding the message headers to your message contract?

This problem usually happens when I make some changes in the WCF service but forget to update the service reference or web reference.

Hope this helps.

EDIT1:

I forgot to mention that when you add a service reference you need to check the box that says something about creating Message Contracts. By default Visual Studio will not create Message Contracts, it only creates data contracts in the WCF client proxy. Only message contracts allow you to access message headers.

Nabheet
  • 1,285
  • 1
  • 12
  • 22
  • I have updated the service reference etc. - that's not the issue. I've tried checking "Always generate message contracts" but the UploadMessage I can create can still only be supplied with the FileByteStream property and not any of the header properties. I reckon my issue is very similar to http://stackoverflow.com/questions/13942113/silverlight-is-not-liking-my-wcf-messagecontract-why?rq=1 I've tried applying the solution but it didn't work.' – John Mayer Apr 15 '13 at 13:31
  • Can you please update the question with all the steps you have tried? Also, did you use SOAP trace or wireshark or SOAP/WCF logging to determine whether your message header was added to the message, if so what was the XML Namespace and does it match the namespace specified in the WSDL? – Nabheet Apr 15 '13 at 13:52