Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums

Go Back   Vista Forums > Vista technology newsgroups > Indigo

Custom SOAP headers

Reply
 
Thread Tools Display Modes
Old 05-14-2008   #1
DonTomasso
Guest
 
Posts: n/a

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

  Reply With Quote

Old 05-15-2008   #2
DonTomasso
Guest
 
Posts: n/a

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
>
  Reply With Quote
Old 1 Week Ago   #3
Lionel Jones
Guest
 
Posts: n/a

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
> >
  Reply With Quote
 
Reply

Thread Tools
Display Modes









Vistax64.com 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 2005-2008

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