Bottom Up Web Service Supporting Flexible Projects
Bottom Up Web Service Supporting Flexible Projects
WTP LogoWTP Home
 

By Kathy Chan
Aug 4, 2005

Introduction
 
 

This document is one of a series of tutorials to demonstrate the use of the Web Services tools in the Web Tools Platform Project using the M5 drivers.

 

This tutorial shows how to create a simple Web service and Web service client from a Java class. The Java class in this scenario converts between the Celsius and Farenheit temperature scales.

 
Set Up
 
 

Before creating the Web service, there are three prerequisites:

  1. Install Apache Tomcat
  2. Set the J2EE Project Module Preference to allow multiple modules per project. Open Window -> Preferences... -> J2EE Project Modules Preference and check the Allow Multiple modules per project option.
  3. Create a Web project
    1. Open File -> New -> Other... -> Web -> Dynamic Web Project to create a new flexible project and Web module.
    2. Click Next.
    3. Enter converter into the Module Name field.
    4. Add a new project by clicking New...
    5. Enter ConverterProject into the Name field.
    6. Ensure that the Target server is set to Apache Tomcat v5.0 . If you have not previously configured a server runtime use the New... button beside the Target server field to do so. Result:


    7. Click Finish to go back to the Dynamic Web Project wizard. Result:


    8. Click Finish .
    9. Say Yes to open the J2EE perspective and you will see the ConverterProject you created listed under Dynamic Web Projects in the Project Explorer view. Expand the ConverterProject project to see its contents.

Creating a bottom up Java bean Web service and Web service client
 
 
  1. Import the wtp/Converter.java class into Converter/JavaSource (be sure to preserve the package).
  2. Select the Converter.java file.
  3. Open File -> New -> Other... -> Web Services -> Web Service.
  4. Click Next.
  5. Select Generate a proxy .
  6. Select Test the Web service .
  7. Select Monitor the Web service .
  8. Select Overwrite files without warning .
  9. Result:


  10. Click Next . Result:


  11. Click Next to get to the Service Deployment Configuration Page . Result:


  12. If you want to choose a server different from the one defaulted by the wizard, click the Edit button to: select a server .
  13. Click Finish .
  14. It will take about one minute for the wizard to assemble the Web service and Web service client Web projects, start Apache Tomcat, and deploy the projects to Tomcat. Once finished, the generated Sample JSP Web application will appear in the browser view, maximized here for clarity:


  15. Under Methods , click on celsiusToFarenheit(float) .
  16. Under Inputs , enter 37 into the celsius entry field.
  17. Click on Invoke. In the Result view, you should get a response of 98.6.


  18. Since you selected the "Monitor Web service" checkbox, a TCP/IP port is automatically created on the Tomcat server. When you invoke the Web service, the TCP/IP Monitor view comes up automatically showing the SOAP message request and response. Double-click on the TCP/IP Monitor view and select XML view in the drop-down combo for both request and response. Result:



Explanation
 

The Web Service wizard is orchestrating the end-to-end generation, assembly, deployment, installation and execution of the Web service, Web service client, and sample JSPs. In this scenario, we clicked Finish on page one. In effect, this is allowing the wizard to pick reasonable defaults according to the basic high-level choices made on the first page. If you repeat this scenario, but use the Next button to work through the wizard, you will learn more about the kinds of choices that are available and the kinds of defaults being assumed.

 

After completing this scenario, the WSDL for the Converter Web service can be found in Converter/WebContent/wsdl/Converter.wsdl.

 

Now that your Web service is running, there are a few interesting things you can do with this WSDL file. Examples:

 
  1. You can double-click on the WSDL to open the WSDL graphical editor.
  2. You can right-click on the WSDL and choose Web Services -> Test with Web Services Explorer to test the service.
  3. You can right-click on the WSDL and choose Web Services -> Publish WSDL file to publish the service to a public UDDI registry.
  4. You can click on the WSDL and choose New -> Other... -> Web Services -> Web Service Client to generate a Web service client. Note, however, that we have already witnessed the internal and visual features of the Web Service Client wizard since, in addition to being its own wizard, it is quite literally embedded within the larger Web Service wizard.