Java Reference
In-Depth Information
Making Asynchronous Calls with a JAX-WS Client
Problem
You want to invoke an operation on your service endpoint interface asynchronously.
Solution
Add the <enableAsyncMapping> custom binding on the server side in the WSDL, then use
one of the invokeAsync methods available on your SEI.
Asynchronous web service clients can be constructed in one of two ways: with a callback, or
with polling. Both methods become available when using a single <enableAsyncMapping>
customization.
NOTE
Before you attempt to call invokeAsync , you need to enable asynchronous mappings on the WSDL
using the jaxws: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 .
With the polling method, the client blocks, checking repeatedly for the response. This is not
suitable for a GUI application where the main thread must be free to keep the application re-
sponsive to user interaction. With the callback method, clients must pass a Handler<T> to
the web service operation at invocation, and the handler object will be populated when the
response is ready. This allows the application thread to continue with other business in the
meantime.
In order to allow a client to invoke an operation asynchronously, you must first specify the
binding customization in a file that you point to during client generation with wsimport .
NOTE
It does not matter what name you give the binding customization file or what extension you use, but
.xml is the convention for JAX-WS custom binding files. This is opposed to .xjb, which is the con-
vention for JAXB custom binding files.
An example of a custom binding file that enables asynchronous mappings is shown in
Example 6-20 .
Search WWH ::




Custom Search