Adding fields to default header

I

IT Drone

I'm trying to consume a Java-based web service, and the RPC style
requires a message that looks like this:


<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<ns1:id soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
soapenv:mustUnderstand="0" xsi:type="soapenc:string"
xmlns:ns1="http://wholesaler.packet8.com/security"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">AA11</ns1:id>
<ns2:login soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
soapenv:mustUnderstand="0" xsi:type="soapenc:string"
xmlns:ns2="http://wholesaler.mycompany.com/security"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">Our
Partner</ns2:login>
<ns3:password
soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
soapenv:mustUnderstand="0" xsi:type="soapenc:string"
xmlns:ns3="http://wholesaler.packet8.com/security"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">password</ns3:password>
</soapenv:Header>
<soapenv:Body>
<ns4:getProductList
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns4="urn:wholesaler.mycompany.com">
<id xsi:type="xsd:string">AA11</id>
</ns4:getProductList>
</soapenv:Body>
</soapenv:Envelope>

Now the problem is that I can't get .net to do:
<Envelope>
<Header>
<login>name></login>
</Header>
etc.

I only seem to be able to get it to do:
<Envelope>
<Header>
<customHeader>
<login>name></login>
</customHeader>
</Header>
etc.

I suspect that I need to use something in System.Xml.Serialization. I
tried just adding
[SoapAttribute( AttributeName = "login")]
public String partnerlogin;

to the top of my proxy class but that didn't seem to get it in the
right place.

How do I modify the proxy class to add these extra three fields I need
to the generated header, without ending up with a new header inside it?



Thanks,

Your faithful IT Drone
 
I

IT Drone

Okay, I'm part way there. I added to my proxy:

SoapType(Namespace="http://schemas.xmlsoap.org/soap/envelope/")]
public sealed class Header : SoapHeader

and declared the elements in it:

[SoapElement("id")]
public String partnerid;

etc.

Then in my invokation code I have:

WholesalerGatewayService.Header myHeader = new
WholesalerGatewayService.Header();

myHeader.partnerlogin="My partner";
myHeader.partnerpassword="password";
myHeader.partnerid="AA11";
So now I have to somehow bind this instance of my overridden header
class back to the instance of my class. How do I do this?

Or am I on the wrong track?
 
I

IT Drone

Nope, it looks like this results in:

<Envelope>
<Header>
<Header>
<!-- this inner one is the one I declared -->
<login>Foo</login>
</Header>
</Header>
<Envelope>

instead of the desired:

<Envelope>
<Header>
<login>Foo</login>
</Header>
<Envelope>

should I be looking at the requestcontext property in WSE as a route to
this?

It's a problem with consuming axis-based web services. I've seen a lot
of other people asking this question on the net, and short of low-level
manipulation of the stream (ugh!) I haven't seen any solutions.
 
I

IT Drone

In case anyone else has this problem, the solution turned out to be
creating a SOAP Extension class and adding a SOAP Extension attribute
to the methods in the client proxy class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top