Java Reference
In-Depth Information
</service>
</definitions>
To begin with, the WS-Addressing element <wsaw:UsingAddressing /> is added to the
WSDL to indicate that clients should use addressing to interact with this service. You can see
that, in general, the exception is treated as a normal SOAP fault would be in a WSDL, with
one addition: the wsaw:Action attribute has been added to the <fault> element associated
with the sayHello operation. Faults will be addressed, using WS-Addressing, to this URI.
The code listing in Example 12-5 represents a client that will invoke that service using WS-
Addressing, including setting the addressing on the fault in the service WSDL.
Example12-5.Addressing client that gets a fault
package com.soacookbook;
import javax.xml.ws.soap.AddressingFeature;
/**
* Calls the WebService with WS-Addressing enabled,
* with the service declaring addressing for an
* exception that can be thrown.
*/
public class AddressingFaultClient {
public static void main(String[] args) {
//do something we know will cause a fault
sayHello(null);
}
private static void sayHello(String name) {
try {
//call Web Service Operation
HelloAddressingFaultsWSService service =
new HelloAddressingFaultsWSService();
//enable WS-Addressing
HelloAddressingFaultsWS port =
service.getHelloAddressingFaultsWSPort(
new AddressingFeature());
String result = port.sayHello(name);
System.out.println("Result = " + result);
} catch (Exception ex) {
ex.printStackTrace();
}
Search WWH ::




Custom Search