SOAP Header creation
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.aspnet.webservices.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Peter Bernhardt
I'm having a problem creating SOAP header in a .NET proxy call a non-.NET
service.

The required SOAP header looks like this:

<soap:Header>
<USER xsi:type="xsd:string">userNameText</USER>
<IP_ADDRESS xsi:type="xsd:string">IPAdressText<IP_ADDRESS>
</soap:Header>

But when I create a class derived from SoapHeader called MySoapHeader in the
proxy contained two public members for the elements I want to include. The
resulting SOAP fragment is this:

<soap:Header>
<q1:MySoapHeader id="h_id1" xmlns:q1="myClient">
<USER xsi:type="xsd:string">userNameText</USER>
<IP_ADDRESS xsi:type="xsd:string">IPAdressText<IP_ADDRESS>
</q1:MySoapHeader>
</soap:Header>

Since the elements are contained within the parent MySoapHeader, the request
fails.

I've tried using separate classes derived from SoapHeader -- USER and
IP_ADDRESS. But how to set the value of the element rather than creating
sub-elements?

As someone who worked with SOAP directly in the past, groping with an extra
layer of abstraction has been very frustrating so far. I'm hoping very much
that I'll see the benefit of this eventually. <8)

TIA,

Peter Bernhardt
SharpSense Software LLC
Click here to reveal e-mail addressRA

********************************
Remove Spanish word for Spam when replying
********************************

Reply to this message...
 
    
Tomas Restrepo \(MVP\) (VIP)
Hi Peter,

[Original message clipped]

I think you got it on that side: The problem is basically that you have two
headers instead of just one. Try something like this on the header
definitions:

[ XmlRoot("USER", Namespace="") ]
public class UserHeader : SoapHeader
{
[ XmlText() ]
public string User;
}
[ XmlRoot("IP_ADDRESS", Namespace="") ]
public class IPHeader : SoapHeader
{
[ XmlText ]
public string IpAddress;
}

(or use the SoapXXX attributes instead of the XmlXXX ones if you're using
rpc/encoded and not doc/literal).

--
Tomas Restrepo
Click here to reveal e-mail address

Reply to this message...
 
    
Peter Bernhardt
Tomas,

Thanks for the response, but I'm still unable to get the desired result.
Using separate classes derived from SoapHeader yields the following:

<soap:Header>
<types:UserHeader id="h_id1">
<USER xsi:type="xsd:string">userValue</USER>
</types:UserHeader>
<types:IPAddressHeader id="h_id2">
<IP_ADDRESS xsi:type="xsd:string">IPAddressValue</USER>
</types:IPAddressHeader>
</soap:Header>

And this is what I actually need:

<soap:Header>
<USER xsi:type="xsd:string">userValue</USER>
<IP_ADDRESS xsi:type="xsd:string">IPAddressValue</USER>
</soap:Header>

..NET is serializing the containing classes derived from SoapHeader. I could
use that if only there was a way to set the value of text element defined
for those types to value of the parameter.

--
Peter Bernhardt
SharpSense Software LLC
Click here to reveal e-mail addressRA

********************************
Remove Spanish word for Spam when replying
********************************
"Tomas Restrepo (MVP)" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Tomas Restrepo \(MVP\) (VIP)
Peter,

[Original message clipped]

Can you show the bit of code you're using for your service? (minus whatever
implementation you have in your WebMethod)

--
Tomas Restrepo
Click here to reveal e-mail address

Reply to this message...
 
    
Peter Bernhardt
I'm only writing a Proxy class for a SOAP client, not the service itself (which is implemented in Java, fwiw) ---

Here's the basic code for the Proxy Class:

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="GetSomethingSoapBinding", Namespace="urn:beanservice")]
public class SomeWSService : System.Web.Services.Protocols.SoapHttpClientProtocol
{
// SOAP Headers
public UserHeader myUser = new UserHeader();
public IPAddressHeader myIPAddress = new IPAddressHeader();

[SoapHeader("myUser")]
[SoapHeader("myIPAddress")]
[SoapRpcMethodAttribute("", RequestNamespace="myClient", ResponseNamespace="urn:beanservice")]
[return: SoapElementAttribute("getSomething")]
public string getSomething()
{

}

[XmlRoot("USER", Namespace="")]
public class UserHeader : SoapHeader
{

[XmlText(typeof(string))]
public string Value;
}

[XmlRoot("IP_ADDRESS", Namespace="")]
public class IPAddressHeader : SoapHeader
{
[XmlText(typeof(string))]
public string Value;
}

}

Again, this is serialzed as follows:

-<soap:Header>
<types:IPAddressHeader id="h_id1">
<Value xsi:type="xsd:string">IPAddressValue</Value>
</types:IPAddressHeader>
<types:UserHeader id="h_id2">
<Value xsi:type="xsd:string">UserValue</Value>
</types:UserHeader>
</soap:Header>

--
Peter Bernhardt
SharpSense Software LLC
Click here to reveal e-mail addressRA

********************************
Remove Spanish word for Spam when replying
********************************
"Tomas Restrepo (MVP)" <Click here to reveal e-mail address> wrote in message news:%Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Tomas Restrepo \(MVP\) (VIP)
Hi Peter,

OK, you got me there... I have to admit I haven't been able to get it to
work, either.... I'll keep trying and see if I can get it going, but if
anyone has any ideas, now's the time to chime in....

--
Tomas Restrepo
Click here to reveal e-mail address

"Peter Bernhardt" <Click here to reveal e-mail address> wrote in message
news:#Click here to reveal e-mail address...
I'm only writing a Proxy class for a SOAP client, not the service itself
(which is implemented in Java, fwiw) ---

Here's the basic code for the Proxy Class:

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="GetSomethingSoapBindin
g", Namespace="urn:beanservice")]
public class SomeWSService :
System.Web.Services.Protocols.SoapHttpClientProtocol
{
// SOAP Headers
public UserHeader myUser = new UserHeader();
public IPAddressHeader myIPAddress = new IPAddressHeader();

[SoapHeader("myUser")]
[SoapHeader("myIPAddress")]
[SoapRpcMethodAttribute("", RequestNamespace="myClient",
ResponseNamespace="urn:beanservice")]
[return: SoapElementAttribute("getSomething")]
public string getSomething()
{

}

Reply to this message...
 
    
Peter Bernhardt
Thanks for your efforts on this, Tomas. I've also addressed this issue to
MS Tech Support. I haven't had any luck with them -- maybe due to the chaos
in Texas?

I thought this would be a simple solution. What I'm trying to do is in
perfect conformance with the SOAP protocol. Ah, well... I hope I don't end
up having to manipulate the underlying XML after it is serialized. That
would be a drag.

Anyway, I'll post the solution here if I ever get it.

--
Peter Bernhardt
SharpSense Software LLC
Click here to reveal e-mail addressRA

********************************
Remove Spanish word for Spam when replying
********************************
"Tomas Restrepo (MVP)" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.ComponentModel.DesignerCategoryAttribute
System.Diagnostics.DebuggerStepThroughAttribute
System.Web.Services.Protocols.SoapHeader
System.Web.Services.Protocols.SoapHttpClientProtocol
System.Web.Services.Protocols.SoapRpcMethodAttribute
System.Web.Services.WebServiceBindingAttribute
System.Xml.Serialization.SoapElementAttribute
System.Xml.XmlText




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com