Using Polling as an Alternative to Callbacks

Some clients of your web services may not be capable of handling callbacks. To learn about situations in which a client may not be able to receive callbacks, see Using Callbacks to Notify Clients of Events.

In order to allow clients that can't accept callbacks to use your web services, you can supply a polling interface as an alternative. In a polling interface, you provide one or more methods that a client can call periodically to determine whether the result of a previous request is ready.

Here is an example taken from the Conversation.jws Sample web service:

    public class Conversation  {
        /**
         * @jws:operation
         * @jws:conversation phase="start"
         */
        public void startRequest()
        {
            ...
        }

        /**
         * @jws:operation
         * @jws:conversation phase="continue"
         */
        public String getRequestStatus()
        {
            ...

        }

        /**
         * @jws:operation
         * @jws:conversation phase="finish"
         */
        public void terminateRequest()
        { }
    }

A client uses the startRequest method to initiate a request. The client may then call getRequestStatus periodically to check on the result. Between calls to getRequestStatus, the client is free to perform other processing. getRequestStatus returns an indication that the request is "pending" until the request is complete. The next time the client calls getRequestStatus after the request is complete, the result will be returned to the client. The client then calls terminateRequest to finish the conversation.

Related Topics

Web Services Development Cycle

Using Asynchrony to Enable Long-Running Operations

Maintaining State with Conversations