Thursday, March 31, 2011

JAX-WS with JBoss 6 Day 6 : SOAP header

SOAP Header is a mechanism for exchanging contextual data like data related WS-Security, WS-Addressing, WS-AtomicTransaction etc.


SOAP Body is meant for exchanging business data. An application also can make use of SOAP Header to exchange custom data that doesn’t belong to the business payload in SOAP Body.

However, the way the data in SOAP Header is populated or accessed depends on how the message parts that go to SOAP Header are defined in WSDL.

The message parts that go to SOAP Header can be defined explicitly or implicitly in a WSDL.

The implicit SOAP Header is defined when message parts that go into SOAP Header are not present in PortType definition. They may appear in Binding definition or don't appear at all in WSDL, although the latter one is a bad idea.

1. header POJO


2. web service


3. generate web service client
wsconsume -k -p jboss.ws.hello.client http://localhost:8080/iJBossWS/ws/testService?wsdl

4. test


5. outbound soap message with header


In an explicit definition, the message parts that go in SOAP Header are present both in PortType and Binding definitions. In this case, JAX-WS generates the service interface with appropriate typed parameter(s) for SOAP Header like it does for SOAP Body.

1. web service


2. generate web service client
wsconsume -k -p jboss.ws.hello.client http://localhost:8080/iJBossWS/ws/testService?wsdl

3. check soap:body definition in wsdl:binding


4. test


5. outbound message


By now you should be able to add info to header when sending request out to web service, but how to read from returned soap message if there is a header and value changed ?

1. web service


2.generate web service client
wsconsume -k -p jboss.ws.hello.client http://localhost:8080/iJBossWS/ws/testService?wsdl

3.check soap:body definition in wsdl:binding


4. test


5. outbound message


6. inbound message

No comments: