Java Reference
In-Depth Information
Asynchronous Invocation with Dispatch
Problem
You are using the SAAJ API's Dispatch class to invoke a web service, and you want to per-
form the invocation asynchronously.
Solution
Create your Dispatch object as you normally would, and instead of calling the invoke meth-
od, call invokeAsync using one of the two supplied methods:
Response<T> invokeAsync(T msg)
Future<?> invokeAsync(T msg, AsyncHandler<T> handler)
Here is an example:
Dispatch<SOAPMessage> dispatch =
service.createDispatch(portQName, SOAPMessage.class,
Service.Mode.MESSAGE);
//Send the request and get the response
Response<Source> bookResponse = dispatch.invokeAsync(request);
Discussion
Other than the fact that you are getting the methods from the Dispatch object, the behavior of
the responses for both polling and callbacks is the same as with an SEI. With this method, you
haven't generated an SEI, but the work being done under the hood is the same, as JAX-WS
reuses SAAJ.
NOTE
Remember that before you attempt to call invokeAsync , you need to enable asynchronous map-
pings on the WSDL using the JAX-WS:bindings element. Otherwise, your invocations may appear
to succeed, but they won't actually be asynchronous. That is, they'll block, just like a normal call to
invoke .
Search WWH ::




Custom Search