Java Reference
In-Depth Information
Defining Operations with Void Return Type
Problem
You want to create a web service operation that does not return any value.
Solution
Define a Java method with a void return type and then add to it the @OneWay annotation.
Discussion
This is perhaps not common, but there are times when you want to update a service with a
new value, and do not need a response. You cannot simply define a Java method with a void
return type. Say that we want to create the following web service operation:
@WebMethod(operationName="update")
public void update(int status) {
System.out.println("The new status is: " + status);
}
The WSDL operation generated from this method will not have the desired effect. It will look
like this:
<operation name="update">
<input message="tns:update" />
<output message="tns:updateResponse" />
</operation>
Of course, we could just go ahead and call it at this point, like this:
//Remember WebServiceRef only works in managed environment
@WebServiceRef(wsdlLocation=
"http://localhost:8080/CalculatorApp/CalculatorWSService?wsdl")
public CalculatorWSService service;
service.getCalculatorWSPort();
port.update(200);
and this invocation would go through using JAX-WS. However, it's not really what we want
because we're getting a result and we're just ignoring it. Moreover, there are SAAJ clients that
would have a hard time with this, as the runtime complains because it's not getting a response
when one is expected (at least according to the WSDL).
Search WWH ::




Custom Search