Life of a Conversation

Each method and callback in a conversational web service plays a specific role in the communication between the web service, its clients, and any Java controls the web service uses. A method may begin a conversation, and a method or callback may continue or end a conversation.

To indicate that a method or callback should participate in a conversation, you can select that method or callback in Design View and set the phase attribute of the conversation property for that method or callback. When you set this property for a method or callback, WebLogic Workshop adds one of the following icons to indicate whether the item starts, continues, or finishes a conversation:

   

To learn more about these attributes, see Implementing Conversations.

To understand how a conversation progresses, let's examine the life cycle of a sample scenario that employs two conversations, one between a web service and its client and another between the web service and a Web Service control. In this example, the BookLocator web service searches a network of book sellers on behalf of a customer. The code within the BookLocator service acts as the middleman and exchanges information between the client and the book seller. The first conversation begins when the client requests a book from the BookLocator service. The BookLocator service then calls the bookSeller service, implemented via a Web Service control, to request the title. When the bookSeller service responds to the BookLocator service, that conversation is complete. The BookLocator then resumes its conversation with the client.

Each of the numbers in the illustration below corresponds to a stage in the life cycle description that follows. Stages 1, 4, 5, and 6 describe the conversation between the BookLocator service and the client. Stages 2 and 3 describe the conversation between the BookLocator service and the bookSeller control.

Stage 1

The client submits a search request by calling the requestBook method, passing information about the book and its author. Code in the requestBook() method saves the book title and author name in member variables as state-related data.

When the request is received, WebLogic Server creates a new context for the service and associates it with the conversation ID. The conversation ID correlates further interactions between the client and the service, ensuring that calls back to the client and calls from other controls are correctly associated with this particular instance of the service.

The requestBook() method has a void return value. The requestBook() method returns immediately, so that the client is not blocked waiting for a response. The result is sent to the client later via the callback.

As the method returns to the client, WebLogic Server starts the conversation's idle and age timers, which may cause the conversation to time out at a later time for lack of activity.

Stage 2

Next, the code executing as part of the requestBook() method's implementation calls the queryForBook() method of the bookSeller service.

Because this method begins a conversation implemented by the bookSeller service, WebLogic Server creates a new context for communication between the BookLocator service and the bookSeller service. This exchange is managed within its own context with its own conversation ID, and is separate from the exchange between the client and the BookLocator service.

Stage 3

After the book seller searches its inventory for the requested book, the bookSeller service returns its results using the onQueryComplete() callback that is part of its interface. This callback finishes the bookSeller service's conversation with the BookLocator service, and WebLogic Server releases its context and state-related data. The conversation context for the BookLocator service remains active.

The response is handled by the BookLocator service through the onQueryComplete() callback handler. The BookLocator service then examines the data returned by the bookSeller service to determine if it is likely to be useful to the client. In this case, the data includes a long list of books of varying condition and price, so the BookLocator service requests more information from the client in order to narrow the list.

Stage 4

The BookLocator service requests more information from the client through the onNeedMoreInfo() callback. Because the callback is part of its interface, the client software is prepared to handle it. The BookLocator service passes to the client information it can use to decide how to narrow the request.

The onNeedMoreInfo() callback continues the conversation with the client; that is, its conversation phase attribute is set to continue. The onNeedMoreInfo() callback is an intermediary step in the conversation.

Stage 5

The client then responds with information to narrow the list, passing that information back to the BookLocator service as parameters of the submitMoreInfo() method. The call to submitMoreInfo(), like the callback made to the client, also continues the conversation.

Stage 6

The BookLocator service uses the additional information to shorten the list, then employs another callback—onSearchComplete()—to send the short list to the client. This callback completes the conversation since the callback’s conversation phase attribute is set to finish. Once the callback has executed, WebLogic Server removes the conversation context and state-related data from memory.

Related Topics

How Do I: Add Support for Conversations?

Implementing Conversations