Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set custom SOAP header using Axis 1.4

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

Here the expected SOAP header:

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

I didn't find any documentation on how to configure this header from an 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 happen with Axis WS client.

How can I set this header in my client calls?

like image 927
razenha Avatar asked Apr 24 '09 15:04

razenha


People also ask

How do I add a SOAP header in WSDL?

You can add soap header information to method calls by decorating the methods in the proxy class generated from the wsdl with the SoapHeader attribute. For example wsdl.exe will generate client proxy class Reference. cs for the web service reference when you "Add Web Reference".

How do you get the SOAP header in JAX WS?

To create a JAX-WS handler to access SOAP header information, first create a basic Java API for XML Web Services (JAX-WS) handlers for your export or import. It will create stubs for the methods. You next need to implement the handleMessage method.

How do you add elements to a SOAP header in Java?

SOAPHeader header = message. getSOAPHeader(); QName headerName = new QName("http://ws-i.org/schemas/conformanceClaim/", "Claim", "wsi"); SOAPHeaderElement headerElement = header. addHeaderElement(headerName); headerElement. addAttribute(new QName("conformsTo"), "http://ws-i.org/profiles/basic/1.1/");


2 Answers

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

MyServiceLocator wsLocator = new MyServiceLocator();
MyServiceSoap ws = wsLocator.getMyServiceSoap(new URL("http://localhost/MyService.asmx"));

//add SOAP header for authentication
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)ws).setHeader(authentication);

//now you can use ws to invoke web services...
like image 74
martsraits Avatar answered Sep 22 '22 12:09

martsraits


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);
like image 45
Joe Zitzelberger Avatar answered Sep 24 '22 12:09

Joe Zitzelberger