Creating a Web service using the Bean2WebService tool

You can use the Bean2WebService tool from a command line to generate a Web service from a Java™ bean using the IBM® WebSphere® run-time environment.

Command line setup

Before using the Bean2WebService tool, you must set up the Web services command line as follows:

  1. From a command prompt, change to install_directory/bin. If you are not sure that you are in the correct directory, this directory should contain several Web service batch files.
  2. Run the following batch script:
    • Windows®: setupenv.bat
    • Linux®: . setupenv.sh
  3. Change to the directory where you want to create your 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 use the Bean2WebService tool to create a Web service.

Creating a Web service

Note: There are two versions of the Bean2WebService tool. If you run the Bean2WebService command, the command will use J2EE 1.4. Alternately you can use the Bean2WebService13 command which will use J2EE 1.3. For any of the commands below you can substitute Bean2WebService13 instead of Bean2WebService if you want to create a Web service that uses J2EE 1.3.

To create a Web service with the Bean2WebService tool, enter the following in the command prompt:

Note: <BeanName> must be the final argument.  See The Bean2WebService tool for a list of mandatory and optional arguments.

Hints:
  • It is recommended that you specify the optional argument: -host <hostname:port>. The default port for the command is 6080, but the default WebSphere Application Server port is 9080.
  • 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.

Example

This is an example of how to use the Bean2WebService tool:

Bean2WebService -host localhost:9080 -cp c:\Working\src -project MyBean
com.ibm.wsdk.MyBean

The main output of the Bean2WebService tool is a file called <ProjectName>EAR.ear in the root of the generated directory structure. The WEB-INF directory is also generated under <ProjectName>. This directory holds the generated WSDL file, Java classes, and so on. If you do not specify the -server-side-only argument, a client-side directory that contains some extra Java files, including serializer and deserializer classes for your complex types, will also be created.

Once you have generated an EAR file, you can deploy it to a server to make it available to others.

Compiling the client implementation code

To compile the client code:
  1. Change to the <ProjectDir> directory, then to the client-side directory.
  2. 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
  3. Enter the following command: buildclient_new

Feedback