ConversationService.java File Example Conversational Web Service .NET Client

4-12 Programming Advanced Features of JAX-RPC Web Services for Oracle WebLogic Server These files are described in detail in the sections that follow.

4.8.1 ConversationService.java File

The example ConversationService.java file is shown in Example 4–1 . The example includes extensive comments that describe its function. Example 4–1 ConversationService.java File package conv; import javax.jws.WebMethod; import javax.jws.WebService; import javax.jws.Oneway; import weblogic.jws.Conversation; import weblogic.jws.Callback; import weblogic.jws.CallbackService; import java.io.Serializable; Demonstrates use of the Conversation annotation to manage the lifetime of the service and provide data persistence and message correlation. Remember that multiple clients might invoke a web service simultaneously. When the web service stores data relevant to the client or calls additional services in order to process a clients request, the service must be able to process returned data from the external services in the context of the specific client it relates to. This is all automatic when conversations are used. Remember that not all clients are capable of accepting callbacks. Specifically, clients operating from behind firewalls may not be able to receive asynchronous callbacks. You may wish to provide a synchronous interface, like this one, for such clients. If a client can accept callbacks, it must send a callback endpoint refrence as part of any start conversation method invocation. To see the behavior in the Test View, invoke startRequest and then getRequestStatus several times quickly. WebServiceserviceName = ConversationService, portName = conversation, targetNamespace = http:www.openuri.org public class ConversationService implements Serializable { Callback public CallbackInterface callback; private boolean useCallbacks; private int num; Starts the conversation ConversationConversation.Phase.START Creating Conversational Web Services 4-13 WebMethod public void startRequestboolean useCallbacks { this.useCallbacks = useCallbacks; } WebMethod ConversationConversation.Phase.CONTINUE public String getRequestStatus { num++; if num == 1 return This is the first time you call getRequestStatus method.; if num == 2 useCallbacks { callback.onResultReadyfinished; return This is the second time you call getRequestStatus method, the conversation has been terminated automtically when the onResultReady callback method is invoked.; } else return You have called getRequestStatus method + num + times; } Used to tell Conversation.jws that the current conversation is no longer needed. WebMethod ConversationConversation.Phase.FINISH public void terminateRequest { } CallbackServiceserviceName = ConversationCallbackService public interface CallbackInterface { Callback to invoke on the client when the external service returns its result. Will only be called it the client can accept callbacks and told us where to send them. p If this callback is used, it implicitly terminates the conversation with no action required on the part of the client. WebMethod Oneway ConversationConversation.Phase.FINISH public void onResultReadyString result; } }

4.8.2 Service.cs File