Using the clientgen Ant Task To Generate Client Artifacts

6-4 Getting Started With JAX-RPC Web Services for Oracle WebLogic Server

6.2.1 Using the clientgen Ant Task To Generate Client Artifacts

The clientgen WebLogic Web services Ant task generates, from an existing WSDL file, the client artifacts that client applications use to invoke both WebLogic and non-WebLogic Web services. These artifacts include: ■ The Java class for the JAX-RPC Stub and Service interface implementations for the particular Web service you want to invoke. ■ The Java class for any user-defined XML Schema data types included in the WSDL file. ■ The JAX-RPC mapping deployment descriptor file which contains information about the mapping between the Java user-defined data types and their corresponding XML Schema types in the WSDL file. ■ A client-side copy of the WSDL file. For additional information about the clientgen Ant task, such as all the available attributes, see Ant Task Reference in the Oracle Fusion Middleware WebLogic Web Services Reference for Oracle WebLogic Server. Update your build.xml file, adding a call to the clientgen Ant task, as shown in the following example: taskdef name=clientgen classname=weblogic.wsee.tools.anttasks.ClientGenTask target name=build-client clientgen wsdl=http:{wls.hostname}:{wls.port}complexComplexService?WSDL destDir=clientclasses packageName=examples.webservices.simple_client type=JAXRPC target Before you can execute the clientgen WebLogic Web service Ant task, you must specify its full Java classname using the standard taskdef Ant task. You must include the wsdl and destDir attributes of the clientgen Ant task to specify the WSDL file from which you want to create client-side artifacts and the directory into which these artifacts should be generated. The packageName attribute is optional; if you do not specify it, the clientgen task uses a package name based on the targetNamespace of the WSDL. The type is also optional; if not specified, it defaults to JAXRPC. In this example, the package name is set to the same package name as the client application, examples.webservices.simple_client. If you set the package name to one that is different from the client application, you would need to import the appropriate class files. For example, if you defined the package name as examples.webservices.complex , you would need to import the following class files in the client application: import examples.webservices.complex.BasicStruct; import examples.webservices.complex.ComplexPortType; import examples.webservices.complex.ComplexService; Invoking Web Services 6-5 If the WSDL file specifies that user-defined data types are used as input parameters or return values of Web service operations, clientgen automatically generates a JavaBean class that is the Java representation of the XML Schema data type defined in the WSDL. The JavaBean classes are generated into the destDir directory. For a full sample build.xml file that contains additional targets from those described in this procedure, such as clean, see Section 6.2.5, Sample Ant Build File for a Java Client. To execute the clientgen Ant task, along with the other supporting Ant tasks, specify the build-client target at the command line: prompt ant build-client See the clientclasses directory to view the files and artifacts generated by the clientgen Ant task.

6.2.2 Getting Information About a Web Service