Enable WS-Addressing for JAX-WS applications
We enable WS-Addressing for JAX-WS applications with addressing annotations. We can also use this method in a client application that uses an injected web service proxy reference.
When enabled, the server processes WS-Addressing inbound SOAP message headers.
Addressing annotations...
- Addressing - 2005/08 WS-Addressing specification.
- SubmissionAddressing - 2004/08 WS-Addressing specification.
When WS-Addressing is required, the server returns a fault message if an inbound SOAP message does not include any WS-Addressing headers, or includes WS-Addressing headers that do not conform to the specification indicated by the annotation, For example, if a client sends a message that includes 2004/08 WS-Addressing headers, and the server requires 2005/08 headers, the server returns a fault message.
On clients, use the Addressing annotation only. The SubmissionAddressing annotation is not supported.
Specify the Addressing annotation in combination with the WebServiceRef annotation, which specifies a reference to the web service proxy injected by the client container.
Annotation settings override settings in the WSDL document. Annotation settings might differ from WSDL settings if we create the WSDL document manually rather than generating it from the code.
Specify up to three optional parameters for each annotation:
Parameter Values Description enabled true (default)
falseWhether WS-Addressing support is enabled. required true
false (default)Whether WS-Addressing headers are required. responses Responses.All (default)
Responses.ANONYMOUS
Responses.NON_ANONYMOUSWhether to use a synchronous or an asynchronous message exchange pattern. Specify Responses.ANONYMOUS to send messages in a synchronous message pattern; use Responses.NON_ANONYMOUS to send messages in an asynchronous message exchange pattern. This parameter is not supported on the SubmissionAddressing annotation.
We can use the Addressing annotation only with a SOAP (1.1 or 1.2) over HTTP binding. If we use the class with another binding, such as XML over HTTP, an exception is thrown on clients, and on servers the web service fails to deploy.
- Use Addressing annotation with no parameters. Default settings apply....
import javax.xml.ws.soap.Addressing; @Addressing @WebService(endpointInterface = "org.apache.axis2.jaxws.calculator.Calculator", serviceName = "CalculatorService", portName = "CalculatorServicePort", targetNamespace = "http://calculator.jaxws.axis2.apache.org")
Enable and require WS-Addressing. The responses attribute is not supported on this annotation.
import com.ibm.websphere.wsaddressing.jaxws21.SubmissionAddressing; @SubmissionAddressing(enabled=true, required=true) @WebService(endpointInterface = "org.apache.axis2.jaxws.calculator.Calculator", serviceName = "CalculatorService", portName = "CalculatorServicePort", targetNamespace = "http://calculator.jaxws.axis2.apache.org")
To enable WS-Addressing support on clients that use an injected web service proxy reference, use the Addressing annotation, with optional parameters as required, in combination with the WebServiceRef annotation. The SubmissionAddressing annotation is not supported for this method. Specify WS-Addressing is enabled, and that the synchronous message exchange pattern is used...
public class MyClientApplication { // Enable Addressing for a port-component-ref resource injection. @Addressing(enabled=true, responses=Responses.ANONYMOUS) @WebServiceRef(MyService.class) private MyPortType myPort; ... }
Notes
If we use the Addressing annotation, and generate a WSDL document from the code, a UsingAddressing element and WS-Policy assertions are created in the WSDL document. Clients that use this WSDL document will include WS-Addressing information in their messages. The SubmissionAddressing annotation is not understood by current WSDL generation tools. However, the WSDL document does not distinguish between the 2005/08 specification and the 2004/08 specification. To generate a WSDL document from code containing a SubmissionAddressing annotation, use both the Addressing and SubmissionAddressing annotations together.
If we specify the responses attribute, the corresponding message exchange pattern will be used.
Related concepts:
IBM proprietary Web Services Addressing SPIs