views:

55

answers:

0

I created a simple webservice, which implements an add operation, and created some client files with wsimport. Now I want to include as less as possible wsdl specific artifacts. Here is an example of how the web service will be called:

String serviceNamespace = "http://jws.samples.geronimo.apache.org/";
String serviceName = "CalculatorServiceService";
QName serviceQN = new QName(serviceNamespace, serviceName);
Service service = Service.create(new URL("http://localhost:8080/WebService/calculator?wsdl"), serviceQN);

String portNamespace = "http://jws.samples.geronimo.apache.org/";
String portName = "CalculatorServicePort";
QName portQN = new QName(portNamespace, portName);
Calculator myProxy = (Calculator) service.getPort(portQN, Calculator.class);

But it seems like I have to include wrapper classes for every message. For example the result message of the add operation:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "addResponse", propOrder = { "_return" })
public class AddResponse {
    @XmlElement(name = "return")
    protected int _return;
    public int getReturn() {
        return _return;
    }
    public void setReturn(int value) {
        this._return = value;
    }
}

These wrappers are used within annotations in the service interface:

@WebService(name = "Calculator", targetNamespace = "http://jws.samples.geronimo.apache.org/")
public interface Calculator {
    @WebMethod
    @RequestWrapper(className = "org.example.webservices.clients.dynamicproxy.Add")
    @ResponseWrapper(className = "org.example.webservices.clients.dynamicproxy.AddResponse")
    public int add(
        @WebParam(name = "value1", targetNamespace = "")
        int value1,
        @WebParam(name = "value2", targetNamespace = "")
        int value2);
}

If the annotations are removed, the web service won't run.

com.sun.xml.ws.model.RuntimeModelerException: runtime modeler error: Wrapper class org.example.webservices.clients.dynamicproxy.jaxws.Add is not found. Have you run APT to generate them?

But why do I need those wrappers? Couldn't JAX-WS create those wrappers on-the-fly? Do you see any information, which couldn't be retrieved from the wsdl file?