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

2-20 Getting Started With JAX-WS Web Services for Oracle WebLogic Server 9. Add the following targets to the build.xml file, used to execute the Main application: path id=client.class.path pathelement path=outputclientclass pathelement path={java.class.path} path target name=run java fork=true classname=examples.webservices.simple_client.Main failonerror=true classpath refid=client.class.path 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. Because the clientgen packageName attribute was set to the same package name as the client application, we are not required to import the clientgen-generated files. package examples.webservices.simple_client; This is a simple Java application that invokes the echoComplexType operation of the ComplexService Web service. public class Main { public static void mainString[] args { ComplexService test = new ComplexService; ComplexPortType port = test.getComplexPortTypePort; 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=JAXWS 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 java target project

2.5 Invoking a Web Service from a WebLogic Web Service