Java Reference
In-Depth Information
Using Addressing in a Java Service
Problem
You want to specify that your web service uses WS-Addressing.
Solution
In your Java web service class, use the
javax.xml.ws.soap.Addressing
annotation along
with the
Action
annotation:
import javax.xml.ws.Action;
import javax.xml.ws.soap.Addressing;
@WebService
@Addressing
public class HelloAddressingWS {
This enables Addressing generally in your service; you must then apply the
Action
annotation
to your operations, like this:
@WebMethod
@Action(
input = "http://soacookbook.com/name",
output = "http://soacookbook.com/greeting")
public String sayHello(String name) { ...
Discussion
The Addressing specification is wrapped into the JAX-WS 2.1 specification, so any vendor
implementing JAX-WS 2.1 will make the Addressing feature available.
The Addressing annotation is used only on an endpoint implementation class. This was im-
plemented as a feature type (
AddressingFeature
) in previous versions of JAX-WS. The new
annotation simplifies usage, but under the hood it all works the same, and the feature instance
is still required in some cases (see
Explicitly Disabling Addressing on the Client
)
.
Let's unpack the code a little bit to see how this works. Adding addressing to your simple
Hello service as you did earlier makes the following changes to the resulting WSDL:
<portType name="HelloAddressingWS">
<operation name="sayHello">
<input wsaw:Action="http://soacookbook.com/name"