File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Basic SOAP Header Question

Raminder Singh
Ranch Hand

Joined: Mar 01, 2002
Posts: 72
Hi,
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:
http://www.javaranch.com/newsletter/May2002/newslettermay2002.jsp#axis .

It says:

String endpoint = "http://localhost:" + options.getPort() +
"/axis/Hello.jws";

call.setOperationName("greet");
call.addParameter("name", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
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>
</ns1:greet>

its ok..!!

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

like:
Request:

<SOAP-ENV:Header>
<ClientID>abc123</ClientID>
<AccountType xsi:type="xsd:string">Credit</AccountType>
</SOAP-ENV:Header>


Response:
<SOAP-ENV:Header>
<TransactionID>TX000123</TransactionID>
</SOAP-ENV:Header>

thanks.
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/TestMsg.java in axis samples).

At the service end you will need message handlers (refer axis samples/echo/echoHeaderStringHandler.java) 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.

~Watsh


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

Joined: Aug 19, 2005
Posts: 2922
    
    5
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
 
Consider Paul's rocket mass heater.
 
subject: Basic SOAP Header Question
 
Similar Threads
Have a question about accessing the SOAP response via VBA client.
AXIS 1.4 Response XML Help-Urgent
impressed
Please Provide The Web Link
SOAPMessage: SAXParseException