views:

1666

answers:

2

I'm trying to consume a .Net 2.0 web service using Axis. I generated the web services client using the Eclipse WST Plugin and it seens ok so far.

Here the expected soap header:

<soap:Header>
<Authentication xmlns="http://mc1.com.br/"&gt;
    <User>string</User>
    <Password>string</Password>
</Authentication>
</soap:Header>

I didn't find any documentation on how can I configure this header from a Axis client. When I generated the client using Visual Studio C# Express 2008, it generates a class named Authentication with two String attributes (User and Password) and all the client methods receive an object of this class as first parameter, but it did not happened with Axis WS client.

How can I set this header in my client calls?

A: 

Maybe you can use org.apache.axis.client.Stub.setHeader method? Something like this:

SOAPHeaderElement authentication = new SOAPHeaderElement("http://mc1.com.br/","Authentication");
SOAPHeaderElement user = new SOAPHeaderElement("http://mc1.com.br/","User", "string");
SOAPHeaderElement password = new SOAPHeaderElement("http://mc1.com.br/","Password", "string");
authentication.addChild(user);
authentication.addChild(password);
stub.setHeader(authentication);

The code might not work exactly like this, I haven't tested it, it's just an example.

martsraits
A: 

If you have an object representing the Authentication container with userid and password, you can do it like so:

import org.apache.axis.client.Stub;

...

MyAuthObj authObj = new MyAuthObj("userid","password"); ((Stub) yourServiceObject).setHeader("urn://your/name/space/here", "partName", authObj);

Joe Zitzelberger