View Single Post
Old 06-26-2008   #3 (permalink)
Lionel Jones
Guest


 

RE: Custom SOAP headers

Could you send me a copy of your code in a notepad file or word at email
address
lioneljones5116@xxxxxx


"DonTomasso" wrote:
Quote:

> I solved it!
> And it was no fun doing so.... This methology must have been developed by
> someone who is totally instituniolized.
>
> I won't show the entire thing, would take too much space, the code for
> modifying the SOAP headers should really be something like;
> client.envelope.headers.add(...), but it's not. If you need to modify the
> headers do a Google for "IClientMessageInspector" and you'll find what you
> need.
>
>
> First off create a class that represents your header:
>
> [DataContract(Namespace = "http://mynamespace.com", Name =
> "MyHeaderClass")]
> public class MyHeaderClass
> {
> private string someValue;
>
> [DataMember]
> public string SomeValue
> {
> get { return someValue; }
> set { someValue= value; }
> }
> }
>
> In the BeforeSendRequest(...) method of your ClientMessageInspector add code
> similar to the code bellow:
>
>
> MessageHeader<MyHeaderClass> header = new MessageHeader<MyHeaderClass>();
>
> MyHeaderClass myHeader = new MyHeaderClass();
> myHeader.SomeValue = "My value";
>
> header.Content = myHeader;
> header.Actor = "Anyone";
>
> System.ServiceModel.Channels.MessageHeader unTypedHeader =
> header.GetUntypedHeader("MyHeaders", ns);
>
> request.Headers.Add(unTypedHeader);
>
> This will give you a SOAP header that looks something like:
>
> <MyHeaders s:actor="Anyone" xmlns="http://mynamespace.com">
> <SomeValue>My Value</SomeValue>
> </MyHeaders>
>
> Custom SOAP headers was a joke in .NET 2.0, and is even worse in 3.5 / wcf.
>
> Now I need to figure out how to extract the outbound headers as well....
> / Thomas
>
>
>
> "DonTomasso" wrote:
>
Quote:

> > I'm trying to modify my soap headers before making a call to a web service.
> > I am using an IClientMessageInspector class and adding a single header works
> > fine, but I want to add a more complex object into the header.
> >
> > The resulting SOAP xml is supposed to look something like this:
> >
> > <soapenv:Header>
> > <myroot>
> > <vala>somevalue</vala>
> > <valb>someothervalue</valb>
> > <valc>a third value</valc>
> > </myroot>
> > </soapenv:Header>
> >
> > I have no clue how to do this.... MessageHeader has no "addNode" or nothing...
> >
> > I'm also currious on how to extract the same type of information in the
> > resulting message.
> >
> > Anyone?
> >
> > Thanx
> > Thomas
> >
My System SpecsSystem Spec