Creating a Web service client using the WSDL2Client Tool
The WSDL2Client tool generates Web service clients that are fully-deployable from one or more WSDL documents and optionally deploys them to the application server.
Prerequisites:
- A WSDL file.
- The fully-qualified path of the directory from which you run the WSDL2Client tool cannot contain a space, or the compile.bat (Linux: compile.sh) and buildclient.bat (Linux: buildclient.sh) scripts will not run properly.
- If you have deselected the WebSphere Server during installation, you will not be able to run buildclient.bat (buildclient.sh for Linux users) if you do not have a Java Development Kit installed.
- Check your system to determine if you have a Java Development Kit installed.
- If you do not, install a JDK. This can be found on the IBM or Sun Web sites.
- After you have installed the JDK, set the JAVA_HOME variable so that it points to the JDK install directory, or put javac in the Path variable.
You use the tool in four stages:
- Run the tool with the -project argument to create skeleton client implementation templates for a Web service that is described by a particular WSDL document.
- Write your implementation code in the templates and compile it using a build script that was generated in stage 1.
- If you have specified the -clientType J2SE option, and you specify your -genMain option, run your client by using the run script that was generated in stage 1.
- If you have specified the -clientType option as Application, EJB or Servlet, run the tool again with the -createEar argument to build a Web-service client-enabled archive from this implementation, and deploy it to the application server.
WSDL2Client tool reference
The WSDL2Client tool generates a client from a Web service's WSDL document.
Parent topic
Creating a Web service with command line tools
Command line setup
Before using the WSDL2WebServiceClient tool, set up the Web services command line as follows:
- From a command prompt, change to Rational Developer products' bin directory.
- Run the following batch script:
- Windows: setupenv.bat
- Linux: . setupenv.sh
- Change to the directory where you want to create the Web service. We will refer to this directory as the command line test directory. Linux: You must have write-access to this directory.
Now, you can run stage 1 of the WSDL2WebServiceClient tool.
Creating a skeleton Web service client implementation
Note: There are two versions of the WSDL2Client tool. If you run the WSDL2Client command, the command will use J2EE 1.4. Alternately you can use the WSDL2Client command which will use J2EE 1.3. For any of the commands below you can substitute WSDL2Client13 instead of WSDL2Client if you want to create a Web service client that uses J2EE 1.3.
To create a skeleton Web service client implementation, enter the following in the command prompt:
- Windows: WSDL2Client [<optional arguments>] -project <ProjectDir> <WSDL URI>
- Linux: WSDL2WebServiceClient.sh [<optional arguments>] -project <ProjectDir> <WSDL URI>
Important:
- The final argument must be <WSDL URI>, which is case-sensitive. See The WSDL2Client tool for a list of optional and mandatory arguments.
- If you plan to Create a Web service client-enabled archive as described below, specify the -clientType argument when creating a skeleton Web service client implementation.
Hint: Note the command line test directory path and the name that you specify for -project. You will need this information to deploy and test your Web service later.
After you have run the tool with the -project <ProjectDir> argument, a directory named "client-side" that contains several subdirectories is created under the specified project. These subdirectories contain all the necessary Java templates, including serializer and deserializer classes for your complex types, and deployment descriptors that are required to build the Web service implementations. If you have specified your -clientType and -genMain options, you will find also a main class implementation template that has been generated for your client type.
A build script called buildclient is also generated to help you compile all this code. If you have run the tool with the -clientType J2SE argument, a run script called runclient is also generated.
Compiling the implementation code
To compile the code:
- Change to the <ProjectDir> directory, then to the client-side directory.
- If your implementation code has dependencies such as a .jar file or a directory that contains .class files, edit the compile script and add the full path names of these dependencies to the USER_CLASSPATH variable. For example:
- Windows: set USER_CLASSPATH = c:\MyJars\webservice.jar;c:\MyClasses
- Linux: USER_CLASSPATH = /home/MyJars/webservice.jar:/home/MyClasses
- Enter the following command: buildclient
Running a J2SE Web service client
To run a J2SE Web-service client:
- Change to the <ProjectDir> directory, then to the client-side directory.
- If your implementation code has dependencies such as a .jar file or a directory that contains .class files, edit the compile script and add the full path names of these dependencies to the USER_CLASSPATH variable. For example:
- Windows: set USER_CLASSPATH = c:\MyJars\webservice.jar;c:\MyClasses
- Linux: USER_CLASSPATH = /home/MyJars/webservice.jar:/home/MyClasses
- Enter the following command: runclient
Creating a Web service client-enabled archive
To create a Web-services client-enabled archive:
- Change to the <WSDK-install-dir>/bin directory.
- Enter the command: WSDL2Client [<optional arguments>] -createEar <File.ear> -clientType <Application | EJB | Servlet> <ProjectDir>
Important:
- The final argument must be <ProjectDir>, and must contain a "client-side" directory.
- In order to successfully run the -createEar argument, specify the -clientType argument when creating a skeleton Web service client implementation as described previously in this task.
After you have written the implementation code, compiled it, and run the tool again with the -createEar <File.ear> argument, the output will be either a new or updated EAR file. You will also notice that the client-side classes that implement the Web service have been moved to the META-INF\classes directory, which is the normal location. If you have specified the -clientType Servlet, you will notice that the client-side classes have been moved to the WEB-INF\classes directory.
Related Tasks
Creating a Web service with command line tools
Testing a Web service generated by the command lineRelated Reference
WSDL2Client tool reference