Windows Vista Forums

Custom SOAP headers
  1. #1


    DonTomasso Guest

    Custom SOAP headers

    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

  2. #2


    DonTomasso Guest

    RE: Custom SOAP headers

    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:

    > 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

  3. #3


    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:

    > 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:
    >

    > > 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

Custom SOAP headers problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Export to csv with custom column headers jmedd PowerShell 1 20 Jan 2009
SOAP headers are not supported by the None MessageVersion. sheir Indigo 0 29 Feb 2008
Custom Mail Headers with Windows Mail GeorgB Vista mail 1 10 Apr 2007
How to sign custom SOAP header? Andrew Slivker Indigo 2 13 Dec 2006
Custom Dependency Property in custom class hierarchy not workingcorrectly?! MueMeister Avalon 0 02 Mar 2006