Introduction to Asynchronous Interfaces
Web applications, including web services, typically use the Hypertext Transport Protocol (HTTP) to provide
communication between a client and a server (the application). HTTP is a request−response protocol. In a
request−response protocol, each operation consists of a request message sent from the client to a server
followed by a response message returned from the server to the client. The server must always send a
response for the operation to complete successfully. Such requests are called synchronous because during the
request the client is synchronized with the server; the client cannot continue processing until the server
responds or the request times out (the client may time out if a response is not received within a specific period
of time).
In a web application, some of the operations the application performs may be long−running. If an operation
involves human interaction such as approval by a loan officer of a bank, the operation could take days to
complete. It would be a poor design if individual request−response cycles were allowed to span days; such
requests would unnecessarily engage resources on both the client and server hosts.
With WebLogic Workshop, you can design your application to be asynchronous, which means that the
application notifies the client when the response is ready. This allows the client to continue performing other
work while the application completes the requested operation. It also keeps each request−response interaction
between the client and application as short as possible.
To create an asynchronous web service, you provide one or more methods that accept requests from clients
that begin an operation but do not wait for the operation to complete. Such methods typically return
immediately, supplying the response portion of the initial request−response interaction but not supplying the
actual result of the requested operation. In an asynchronous interface, you also provide a mechanism for the
client to obtain the results of the long−running operation when the results are ready. There are two ways to
accomplish this:
Implement methods that initiate requests and define callbacks to send results.•
Implement methods that initiate requests, methods that return request status (for example, "pending"
or "complete") and methods the return results. This approach is referred to as a polling interface.
•
Using Callbacks
When you define a callback for a web service, you are defining a message for the web service to send to the
client that notifies the client of an event that has occurred in your web service. In this design, the client first
calls the web service with a request. This request call typically returns immediately (completing the first
request−response interaction), meaning that the client does not have to wait for the operation to be completed.
The client can now continue doing other tasks. When the web service or Java control has finished processing
the client's request, it sends a callback, that is, it sends a message back to the client notifying it that the request
has been processed and/or providing the results. Note that a callback constitutes a second request−response
interaction in which the request (not the response) is sent to the client. To learn more about the callback
mechanism, see Using Callbacks to Notify Clients of Events.
To use a callback, two requirements must be met. First, if a web service defines a callback the web service
must be conversational. Conversational web services keep track of the originator of a request and can
therefore send the callback to the appropriate caller. Secondly, the client must be capable of receiving and
interpreting the callback. If the callback is defined by a web service, then in essence the client must itself be a
web service since it must be capable of receiving messages. It must also be capable of correlating an incoming
message with a previous request that it initiated. To learn more about conversations, see Designing
Introduction to Asynchronous Interfaces 3