Invoking a Web Service Using Asynchronous Request-Response 2-9
4.
Use the post-call context methods to operate on the asynchronous context after the asynchronous method is called. The following example uses the getProperty
method of the post-call context to get the property that was set by pre-call context before invoking the asynchronous method:
String userName = Stringapc.getPropertyuserName;
2.4.3 Example of a Synchronous Invoke
The following example shows a JWS file that invokes the getQuote operation of the StockQuote
Web service synchronously. The example is shown only so you can compare it with the corresponding asynchronous invoke shown in
Section 2.4, Writing the Asynchronous JWS File
. package examples.webservices.async_req_res;
import weblogic.jws.WLHttpTransport; import weblogic.jws.ServiceClient;
import javax.jws.WebService; import javax.jws.WebMethod;
import java.rmi.RemoteException; WebServicename=SyncClientPortType,
serviceName=SyncClientService, targetNamespace=http:examples.org
WLHttpTransportcontextPath=syncClient, serviceUri=SyncClient,
portName=SyncClientPort
Normal service-to-service client that invokes StockQuote service synchronously.
public class SyncClientImpl { ServiceClientwsdlLocation=http:localhost:7001asyncStockQuote?WSDL,
serviceName=StockQuoteService, portName=StockQuote private StockQuotePortType port;
WebMethod public void nonAsyncOperationString symbol throws RemoteException {
int quote = port.getQuotesymbol;
System.out.println-------------------; System.out.printlnGot quote + quote ;
System.out.println-------------------;
} }
2-10 Programming Advanced Features of JAX-RPC Web Services for Oracle WebLogic Server
2.5 Updating the build.xml File When Using Asynchronous Request-Response
To update a build.xml file to generate the JWS file that invokes a Web service operation asynchronously, add taskdefs and a build-clientService target that
looks something like the following; see the description after the example for details:
taskdef name=jwsc classname=weblogic.wsee.tools.anttasks.JwscTask
target name=build-clientService jwsc
enableAsyncService=true srcdir=src
destdir={clientService-ear-dir}
jws file=exampleswebservicesasync_req_resStockQuoteClientImpl.java
clientgen wsdl=http:{wls.hostname}:{wls.port}asyncStockQuote?WSDL
packageName=examples.webservices.async_req_res
jws jwsc
target Use the taskdef Ant task to define the full classname of the jwsc Ant tasks.
Update the jwsc Ant task that compiles the client Web service to include a clientgen
child element of the jws element so as to generate and compile the JAX-RPC stubs for the deployed StockQuote Web service. The jwsc Ant task
automatically packages them in the generated WAR file so that the client Web service can immediately access the stubs. By default, the jwsc Ant task in this case generates
both synchronous and asynchronous flavors of the Web service operations in the JAX-RPC stubs. You do this because the StockQuoteClientImpl JWS file imports
and uses one of the generated classes.
2.6 Disabling The Internal Asynchronous Service
By default, every WebLogic Server instance deploys an internal asynchronous Web service that handles the asynchronous request-response feature. To specify that you do
not want to deploy this internal service, start the WebLogic Server instance using the -Dweblogic.wsee.skip.async.response=true
Java system property. One reason for disabling the asynchronous service is if you use a WebLogic Server
instance as a Web proxy to a WebLogic cluster. In this case, asynchronous messages will never get to the cluster, as required, because the asynchronous service on the
proxy server consumes them instead. For this reason, you must disable the asynchronous service on the proxy server using the system property.
For details on specifying Java system properties to configure WebLogic Server, see Specifying Java Options for a WebLogic Server Instance in Managing Server Startup
and Shutdown for Oracle WebLogic Server.