Compiling and Running the Client Application

Invoking Web Services 6-7 + , + result.getStringValue; } } In the preceding example: ■ The following code shows how to create a ComplexPortType stub: ComplexService service = new ComplexService_Impl args[0] + ?WSDL; ComplexPortType port = service.getComplexServicePort; The ComplexService_Impl stub factory implements the JAX-RPC Service interface. The constructor of ComplexService_Impl creates a stub based on the provided WSDL URI args[0] + ?WSDL. The getComplexServicePort method is used to return an instance of the ComplexPortType stub implementation. ■ The following code shows how to invoke the echoComplexType operation of the ComplexService Web service: BasicStruct result = port.echoComplexTypein; The echoComplexType operation returns the user-defined data type called BasicStruct . The method of your application that invokes the Web service operation must throw or catch java.rmi.RemoteException and javax.xml.rpc.ServiceException, both of which are thrown from the generated JAX-RPC stubs.

6.2.4 Compiling and Running the Client Application

Add javac tasks to the build-client target in the build.xml file to compile all the Java files both of your client application and those generated by clientgen into class files, as shown by the bold text in the following example: target name=build-client clientgen wsdl=http:{wls.hostname}:{wls.port}complexComplexService?WSDL destDir=clientclasses packageName=examples.webservices.simple_client type=JAXRPC javac srcdir=clientclasses destdir=clientclasses includes=.java javac srcdir=src destdir=clientclasses includes=exampleswebservicessimple_client.java target In the example, the first javac task compiles the Java files in the clientclasses directory that were generated by clientgen, and the second javac task compiles the Java files in the exampleswebservicessimple_client subdirectory of the current directory; where it is assumed your Java client application source is located. In the preceding example, the clientgen-generated Java source files and the resulting compiled classes end up in the same directory clientclasses. Although this might be adequate for prototyping, it is often a best practice to keep source code even generated code in a different directory from the compiled classes. To do this, set the destdir for both javac tasks to a directory different from the srcdir directory. 6-8 Getting Started With JAX-RPC Web Services for Oracle WebLogic Server You must also copy the following clientgen-generated files from clientgens destination directory to javacs destination directory, keeping the same subdirectory hierarchy in the destination: packageNameServiceName_internaldd.xml packageNameServiceName_java_wsdl_mapping.xml packageNameServiceName_saved_wsdl.wsdl where packageName refers to the subdirectory hierarchy that corresponds to the package of the generated JAX-RPC stubs and ServiceName refers to the name of the Web service. To run the client application, add a run target to the build.xml that includes a call to the java task, as shown below: path id=client.class.path pathelement path=clientclasses 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 arg line=http:{wls.hostname}:{wls.port}complexComplexService target The path task adds the clientclasses directory to the CLASSPATH. The run target invokes the Main application, passing it the URL of the deployed Web service as its single argument. See Section 6.2.5, Sample Ant Build File for a Java Client