Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Indigo

Vista - Custom SOAP headers

 
 
Old 05-14-2008   #1 (permalink)
DonTomasso


 
 

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
Old 05-15-2008   #2 (permalink)
DonTomasso


 
 

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:
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
Old 06-26-2008   #3 (permalink)
Lionel Jones


 
 

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
 

Thread Tools


Similar Threads
Thread Forum
Export to csv with custom column headers PowerShell
Custom Mail Headers with Windows Mail Vista mail


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46