Programming Guidelines for the JWS File That Invokes a Conversational Web Service

Creating Conversational Web Services 4-7

4.4 Programming Guidelines for the JWS File That Invokes a Conversational Web Service

The following example shows a simple JWS file for a Web service that invokes the conversational Web service described in Section 4.3, Programming Guidelines for the Conversational JWS File ; see the explanation after the example for coding guidelines that correspond to the Java code in bold. package examples.webservices.conversation; import weblogic.jws.WLHttpTransport; import weblogic.jws.ServiceClient; import weblogic.wsee.conversation.ConversationUtils; import javax.jws.WebService; import javax.jws.WebMethod; import javax.xml.rpc.Stub; import examples.webservices.conversation.ConversationalPortType; import java.rmi.RemoteException; WebServicename=ConversationalClientPortType, serviceName=ConversationalClientService, targetNamespace=http:examples.org WLHttpTransportcontextPath=convClient, serviceUri=ConversationalClient, portName=ConversationalClientPort client that has a conversation with the ConversationalService. public class ConversationalClientImpl { ServiceClient wsdlLocation=http:localhost:7001convConversationalService?WSDL, serviceName=ConversationalService, portName=ConversationalServicePort private ConversationalPortType port; WebMethod public void runConversationString message { try { Invoke start operation String result = port.start; System.out.printlnstart method executed.; System.out.printlnThe message is: + result; Invoke continue operation result = port.middlemessage ; System.out.printlnmiddle method executed.; System.out.printlnThe message is: + result; 4-8 Programming Advanced Features of JAX-RPC Web Services for Oracle WebLogic Server Invoke finish operation result = port.finishmessage ; System.out.printlnfinish method executed.; System.out.printlnThe message is: + result; ConversationUtils.renewStubStubport; } catch RemoteException e { e.printStackTrace; } } } Follow these guidelines when programming the JWS file that invokes a conversational Web service; code snippets of the guidelines are shown in bold in the preceding example: ■ Import the ServiceClient JWS annotation: import weblogic.jws.ServiceClient; ■ Optionally import the WebLogic utility class for further configuring a conversation: import weblogic.wsee.conversation.ConversationUtils; ■ Import the JAX-RPC stub of the port type of the conversational Web service you want to invoke. The actual stub itself will be created later by the jwsc Ant task. The stub package is specified by the packageName attribute of the clientgen child element of jws, and the name of the stub is determined by the WSDL of the invoked Web service. import examples.webservices.conversation.ConversationalPortType; ■ In the body of the JWS file, use the ServiceClient JWS annotation to specify the WSDL, name, and port of the conversational Web service you want to invoke. You specify this annotation at the field-level on a private variable, whose data type is the JAX-RPC port type of the Web service you are invoking. ServiceClient wsdlLocation=http:localhost:7001convConversationalService?WSDL, serviceName=ConversationalService, portName=ConversationalServicePort private ConversationalPortType port; ■ Using the stub you annotated with the ServiceClient annotation, invoke the start operation of the conversational Web service to start the conversation. You can invoke the start method from any location in the JWS file constructor, method, and so on: String result = port.start; ■ Optionally invoke the continue methods to continue the conversation. Be sure you use the same stub instance so that you continue the same conversation you started: result = port.middlemessage ; Creating Conversational Web Services 4-9 ■ Once the conversation is completed, invoke the finish operation so that the conversational Web service can free up the resources it used for the current conversation: result = port.finishmessage ; ■ If you want to reuse the Web service conversation stub to start a new conversation, you must explicitly renew the stub using the renewStub method of the weblogic.wsee.conversation.ConversationUtils utility class: ConversationUtils.renewStubStubport;

4.5 ConversationUtils Utility Class