Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Web Services and the fly likes Basic SOAP Header Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Basic SOAP Header Question" Watch "Basic SOAP Header Question" New topic

Basic SOAP Header Question

Raminder Singh
Ranch Hand

Joined: Mar 01, 2002
Posts: 72
I'm new to Web Services and usually run some demo code to understand what actually is going there (it helps me in understanding the tutorials easily).

I had successfully tested 'hello' example on axis ref: .

It says:

String endpoint = "http://localhost:" + options.getPort() +

call.addParameter("name", XMLType.XSD_STRING, ParameterMode.IN);
String msg = (String)call.invoke(new Object[] {args[0]});
System.out.println("Reply: " + msg);

converts to:

<ns1:greet xmlns:ns1="http://localhost:8080/axis/Hello.jws">
<name xsi:type="xsd:string">Greg</name>

its ok..!!

but i want to know, how to add soap header values to our request and response custome code?


<AccountType xsi:type="xsd:string">Credit</AccountType>


Watsh Rajneesh
Ranch Hand

Joined: Apr 17, 2006
Posts: 110
An easy way to send out a SOAP message with header is:

Note: Modify the header and body per your requirement. Above source is from samples/message/ in axis samples).

At the service end you will need message handlers (refer axis samples/echo/ which can process both soap request and response to produce the required header in the response soap message.

At the client you can read the response header as follows:

MessageContext mc = call.getMessageContext();
Vector headerVec = mc.getResponseMessage().getSOAPEnvelope().getHeaders();
You can explore further on these lines.


SCJP 5.0 (90%), SCDJWS 1.4 (88%), SCWCD 1.4 (82%), SCBCD 1.3 (85%)
Peer Reynders

Joined: Aug 19, 2005
Posts: 2933
From the Web Services FAQ
Tip: Better SOAP interfaces with header elements
Web services programming tips and tricks: Using SOAP headers with JAX-RPC
Web services programming tips and tricks: Extend JAX-RPC Web services using SOAP headers
I agree. Here's the link:
subject: Basic SOAP Header Question
jQuery in Action, 3rd edition