WCF custom SOAP headers - Silverlight RRS feed

  • Question




    I've been using IClientMessageInspector to add custom information to my SOAP header, as a method for managing state across our client and lots of WCF services.


    However, recently we decided to convert all our client apps to Silverlight 2.0. So I created a Silverlight class library to implement the same interface (i.e. IClientMessageInspector). Argh! It's not supported in Silverlight! Much wailing and gnashing of teeth.


    After I'd calmed down, I decided there MUST be a way to add custom information into the SOAP header when binding over basicHttpBinging in Silverlight. Nobody would develop a platform that wouldn't let you do that, would they?

    So my question is: Where are the hooks into the WCF stack in the Silverlight CLR? Specifically, where can I hook into the outgoing header?


    Please help!


    Thanks in advance



    Thursday, July 3, 2008 2:16 PM


All replies

  • On SL2 Beta2, the way to add additional SOAP headers in a request is to use an untyped message contract (in a way similar to the one described at It may also be possible to do that by creating a new channel, although I haven't tried it.


    For RTM we're strongly considering adding support for using the operation context to make adding headers a lot easier, as this is one of the most frequent requests we've received so far.

    Thursday, July 3, 2008 5:05 PM
  • Thanks for the reply Carlos.


    I have looked at using MessageContracts to achieve this (albeit typed ones, not anonymous). When I import the service into Silverlight, the [MessageContract] class properties are missing the [MessageHeader] attribute. I understand that Silverlight doesn't support this, but will this approach still work? i.e. will my properties get added to the SOAP header and appear on the server?






    Friday, July 4, 2008 12:33 PM
  • Unfortunately not in this release. The [MessageHeaderAttribute] is not defined in SL2, so the properties will not be added to the soap headers when sent by the client.
    Monday, July 7, 2008 5:25 PM
  • Hi Carlos,


    You mentioned that it might be possible to create a custom channel in Silverlight - I'd guess you mean an IRequestChannel. I've found an example that does more or less this, but sadly the example is for full-fat .NET. I can't seem to convert this to Silverlight, due to some 'missing' parts.


    Do you have any examples on how I could create a custom channel in Silverlight?






    Saturday, July 12, 2008 11:21 AM
  • Actually, I've figured it out for myself! I'll put the code on my blog some time soon.




    Saturday, July 12, 2008 10:40 PM
  • Hi Carlos,


    I was wondering if, within Silverlight, there is any way to create a custom listener so that I might be able to read custom SOAP header information as well as write it? I've got the custom channel working beautifully and it would make my life complete if I could just complete the circle, so to speak.


    Thanks in advance




    Monday, July 21, 2008 11:43 AM
  • Can I get a sample code to add custom SOAP Headers to WCF Calls from a silverlight application?


    Wednesday, August 6, 2008 3:24 PM
  • Sure.


    Look here.



    Tuesday, August 19, 2008 9:27 AM