BlackBerry
Skip Top Navigation
Developers Partners
North America [change region] Products Solutions Purchasing Support
Developers


Create a Web Service Interface and WSDL File

Exercise

In this lab you will create a web service interface using Java™ that describes the calculator operations the web service will provide. Using this interface, you will then generate a standard WSDL file.

Prerequisites

  • None

Objectives

  • Discover how to create a web service interface.
  • See how to describe the operations of a calculator with a Java interface.
  • Discover how to generate the WSDL file for the web service based on the interface created previously.

Setup Tasks

The following software is required to perform this series of labs:
Application server: Apache Tomcat
Web service platform: Apache Axis

Tasks:

Create a Web Service Interface

  1. Create a new file with the following Java interface:
        package calculator;
        public interface Calculator{
            public double add( double a, double b ); // returns a plus b
            public double subtract( double c, double d ); // returns c minus d
        }
  2. Save the file as Calculator.java.
  3. Compile the file. (Note: make sure the Calculator.class is located under calculator folder)

Generate a WSDL File

  1. Verify that the Axis libraries are in your class path.
  2. To generate the WSDL file, run Java2WSDL with the required arguments.
        % java org.apache.axis.wsdl.Java2WSDL –o calc.wsdl –y WRAPPED 
        –l"http://localhost:8080/axis/services/calculator" –n "urn:calculator" 
        –p"calculator" "urn:calculator" calculator.Calculator
Argument Description
-o calc.wsdl name of the output WSDL
-y WRAPPED web service style
-l "http://localhost:8080/axis/services/calculator" web service location
-n "urn:calculator" target namespace of the WSDL file
-p "calculator" "urn:calculator" mapping from a package to a namespace; there might be multiple mappings
calculator.Calculator Java interface for the web service

Check Your Work

Download the completed code:
Calculator.java
Calc.wsdl

Additional Labs

Go to the next exercise in “Building a Calculator Web Service Using Apache Tomcat/Axis”, Generate Server Stubs Using Apache Axis WSDL2Java.

Back to the Developer Lab Main Menu

 
     
 Home | Products | Solutions | Purchasing | Support | Developers | Worldwide | News | About Us | Contact Us | Site Map
 Legal | Copyright © 2008 Research In Motion Limited, unless otherwise noted.