Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Basic SOAP Header Question

 
Raminder Singh
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic