File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes Axis Client Headers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Axis Client Headers" Watch "Axis Client Headers" New topic

Axis Client Headers

Mike Litherland
Ranch Hand

Joined: Aug 12, 2004
Posts: 31

I've created client stubs for a SOAP service using the Axis WSDL2Java program. With the '-a' switch it produces a stub for the headers that the service requires. The problem that I have is that there doesn't appear to be a way to tell your client program to use the header object you create. I've found some hints online that tell you how to create a header without using the stub code, but it seems there really ought to be a way.

Has anybody overcome this obstacle?

Ray Thomas

Joined: Feb 24, 2005
Posts: 7
Even though this question was posted quite a while back, I just saw it while searching for something else so here's an answer:

Supposing that the class generated for the header info is MyHeaderType and the generated stub class (MyWebServiceStub) instance is assigned to a variable named binding, then:

MyHeaderType header = new MyHeaderType("param1", "param2", "paramEtc");
binding.addHeader("", "urn:MyWebServiceNamespace", header);

Just couldn't stand to see a question without an answer. Hope my answer works for somebody besides me.
Mark Newton
Ranch Hand

Joined: Jan 31, 2006
Posts: 129

Just wanted to say thanks to both of you guys - I had the same problem, and hadn't even found the -a switch, so that was helpful in itself!

I actually needed to use a slightly different solution from the one Ray suggested, and I also needed a slight intellectual leap, which wasn't immediately obvious from his answer, so I'll show my solution here, just in case:

As with Ray, my class generated for the header info will be MyHeaderType, and the instance of my generated Stub class is binding.

I actually had to cast binding, and the relevant line reads:

Where http://.../... represents the namespace of the WSDL, tns:MyHeaderType is the name of the type required in my header (taken from the WSDL), and header is an instance of MyHeaderType.

Not sure about the difference between my setHeader(), and Ray's addHeader() methods, but I couldn't find an addHeader() method, and setHeader() works just fine!

Hope this is helpful to someone.
I agree. Here's the link:
subject: Axis Client Headers
It's not a secret anymore!