Java Reference
In-Depth Information
The client in Example 12-1 can be built to invoke the simple Hello service from Using Ad-
dressing in a Java Service . This class assumes that you have performed a wsimport (or equi-
valent) and added the generated artifacts to your classpath. Example 12-4 in Addressing Faults
shows how to use the AddressingFeature class with a service port object to enable WS-Ad-
dressing on the client.
Example12-1.AddressingClient.java
import javax.xml.ws.soap.AddressingFeature;
/**
* Calls the WebService with WS-Addressing enabled.
*/
public class AddressingClient {
public static void main(String...args) {
try { // Call Web Service Operation
HelloAddressingWSService service = new
HelloAddressingWSService();
//enable WS-Addressing
HelloAddressingWS port =
service.getHelloAddressingWSPort(
new AddressingFeature());
String result = port.sayHello("Eben");
System.out.println("Result = "+result);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
So all you have to do is create a new AddressingFeature using the default constructor. There
are two Boolean arguments that you can optionally pass to the constructor as well, indicating
preferences for “required” and “enabled.”
Running this client produces a SOAP request that looks like this, including the HTTP headers:
SOAPAction: "http://soacookbook.com/name"
Content-Type: text/xml;charset="utf-8"
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header>
<To xmlns="http://www.w3.org/2005/08/addressing">
http://localhost:7777/TestWS/HelloAddressingWSService
</To>
Search WWH ::




Custom Search