Asynchronously Calling a JAX-WS Web Service Operation
See Also
When a client calls a JAX-WS web service operation asynchronously,
the client does not need to wait for the response to be received.
When a client use this communication style, it consumes the web services either
through the "polling" approach or the "callback" approach.
- Polling. The client invokes a web service
method and
repeatedly asks for the result. Polling is a
blocking operation because
it blocks the calling thread, which is why you
do not want to use it in a GUI application.
- Callback. The client passes a callback
handler during the web service method invocation. The handler's
handleResponse() method is called when the result is
available.
This approach is suitable to GUI applications because you do not
have to wait for the response. For example, you make a call from
a GUI event handler and return control immediately, keeping the
user interface responsive.
Note: You can use the IDE to generate skeleton
asynchronous methods, as explained below.
To call a web service operation asynchronously:
- Create a web service client.
- If the web service client is deployed from a web application, you can call the
web service from a servlet or from a JSP page. If the web service client is deployed from
a Java application, use a Java source file instead. So, do one of the following:
- Create a Java source file, such as a servlet.
- Use the default index.jsp file that is created for you when you create
a web application or a JSP file.
- In the Projects window, expand the Web Service References node, right-click the web service node (the first node
within the Web Service References node), and choose Edit Web Service Attributes.
- In the Edit Web Service Attributes editor, within the PortType Operations node,
expand the node with the same name
as the web service operation you want to invoke.
- Select Enable Asynchronous Client. Click OK.
- Open the file in the Source Editor and do one of the following:
- Expand the Web Service References node and continue expanding subnodes until
you get to the node representing the asynchronous operation. Using your mouse, drag and drop
the node to where you need it to be in the file.
- Right-click in the method (for Java files) or anywhere in the Source Editor (for JSP file)
from where you want to call the web service, and choose Insert Code
> Call Web Service Operation. The Select Operation to Invoke dialog box appears.
Expand the nodes and select the asynchronous operation. Click OK.
The IDE adds the code required for asynchronously calling the web service to the file.
- See Also
- About Web Services
Legal Notices