Sample Java Client Application Sample Ant Build File For Building Java Client Application

2-20 Getting Started With JAX-RPC Web Services for Oracle WebLogic Server target name=run java fork=true classname=examples.webservices.simple_client.Main failonerror=true classpath refid=client.class.path arg line=http:{wls.hostname}:{wls.port}complexComplexService java target The run target invokes the Main application, passing it the WSDL URL of the deployed Web service as its single argument. The classpath element adds the clientclass directory to the CLASSPATH, using the reference created with the path task. 10. Execute the run target to invoke the echoComplexType operation: prompt ant run If the invoke was successful, you should see the following final output: run: [java] echoComplexType called. Result: 999, Hello Struct You can use the build-client and run targets in the build.xml file to iteratively update, rebuild, and run the Java client application as part of your development process.

2.4.1 Sample Java Client Application

The following provides a simple Java client application that invokes the echoComplexType operation. package examples.webservices.simple_client; import java.rmi.RemoteException; import javax.xml.rpc.ServiceException; import the BasicStruct class, used as a param and return value of the echoComplexType operation. The class is generated automatically by the clientgen Ant task. import examples.webservices.complex.BasicStruct; This is a simple Java client application that invokes the echoComplexType operation of the ComplexService Web service. public class Main { public static void mainString[] args throws ServiceException, RemoteException { ComplexService service = new ComplexService_Impl args[0] + ?WSDL ; ComplexPortType port = service.getComplexServicePort; BasicStruct in = new BasicStruct; in.setIntValue999; in.setStringValueHello Struct; BasicStruct result = port.echoComplexTypein; System.out.printlnechoComplexType called. Result: + result.getIntValue + , + result.getStringValue; } } Use Cases and Examples 2-21

2.4.2 Sample Ant Build File For Building Java Client Application

The following build.xml file defines tasks to build the Java client application. The example uses properties to simplify the file. project name=webservices-simple_client default=all -- set global properties for this build -- property name=wls.hostname value=localhost property name=wls.port value=7001 property name=example-output value=output property name=clientclass-dir value={example-output}clientclass path id=client.class.path pathelement path={clientclass-dir} pathelement path={java.class.path} path taskdef name=clientgen classname=weblogic.wsee.tools.anttasks.ClientGenTask target name=clean delete dir={clientclass-dir} target target name=all depends=clean,build-client,run target name=build-client clientgen type=JAXRPC wsdl=http:{wls.hostname}:{wls.port}complexComplexService?WSDL destDir={clientclass-dir} packageName=examples.webservices.simple_client javac srcdir={clientclass-dir} destdir={clientclass-dir} includes=.java javac srcdir=src destdir={clientclass-dir} includes=exampleswebservicessimple_client.java target target name=run java fork=true classname=examples.webservices.simple_client.Main failonerror=true classpath refid=client.class.path arg line=http:{wls.hostname}:{wls.port}complexComplexService java target project

2.5 Invoking a Web Service from a WebLogic Web Service