Java API for XML-Based Web Services (JAX-WS) provides support for invoking web services using an asynchronous client invocation. JAX-WS provides support for both a callback and polling model when calling web services asynchronously. Both the callback model and the polling model are available on the Dispatch client and the Dynamic Proxy client.
Develop a JAX-WS Dynamic Proxy or Dispatch client. When developing Dynamic Proxy clients, after you generate the portable client artifacts from a Web Services Description Language (WSDL) file using the wsimport command, the generated service endpoint interface (SEI) does not have asynchronous methods included in the interface. Use JAX-WS bindings to add the asynchronous callback or polling methods on the interface for the Dynamic Proxy client. To enable asynchronous mappings, you can add the jaxws:enableAsyncMapping binding declaration to the WSDL file. For more information on adding binding customizations to generate an asynchronous interface, see chapter 8 of the JAX-WS specification.
An asynchronous invocation of a web service sends a request to the service endpoint and then immediately returns control to the client program without waiting for the response to return from the service. JAX-WS asynchronous web service clients consume web services using either the callback approach or the polling approach. Using a polling model, a client can issue a request and receive a response object that is polled to determine if the server has responded. When the server responds, the actual response is retrieved. Using the callback model, the client provides a callback handler to accept and process the inbound response object. The handleResponse() method of the handler is called when the result is available. Both the polling and callback models enable the client to focus on continuing to process work without waiting for a response to return, while providing for a more dynamic and efficient model to invoke web services. Polling invocations are valid from Enterprise JavaBeans (EJB) clients or Java Platform, Enterprise Edition (Java EE) application clients. Callback invocations are valid only from Java EE application clients.
<soapenv:Header> <wsa:To>http://target.bar.com:81/LiteSecurityService/SecurityService</wsa:To> <wsa:ReplyTo> <wsa:Address>http://myhost:2146/axis2/services/LiteSecurityService. WSRMServicePort/AnonOutInOp?IBMwebservicesID=922A5DC38A337C4CEF1168347862705 </wsa:Address> </wsa:ReplyTo> <wsa:MessageID>urn:uuid:922A5DC38A337C4CEF1168347862403</wsa:MessageID> <wsa:Action>getEndpointReference</wsa:Action> </soapenv:Header>To resolve this issue, configure the client to send the location details for the asynchronous listener in IP format, by adding the following system property to the Java virtual machine. Note that by transmitting the IP address, you lose the benefits of DHCP.
-Dcom.ibm.websphere.webservices.transportEPRInIPAddr=yesgotcha
@WebService public interface CreditRatingService { // Synchronous operation. Score getCreditScore(Customer customer); // Asynchronous operation with polling. Response<Score> getCreditScoreAsync(Customer customer); // Asynchronous operation with callback. Future<?> getQuoteAsync(Customer customer, AsyncHandler<Score> handler); }
CreditRatingService svc = ...; Future<?> invocation = svc.getCreditScoreAsync(customerTom, new AsyncHandler<Score>() { public void handleResponse ( Response<Score> response) { score = response.get(); // process the request... } } );
CreditRatingService svc = ...; Response<Score> response = svc.getCreditScoreAsync(customerTom); while (!response.isDone()) { // Do something while we wait. } score = response.get();
In this information ...Related tasks
Related reference
| IBM Redbooks, demos, education, and more(Index) |