The WSIT Tutorial

Creating a Web Service

The starting point for developing a web service to use WSIT is a Java class file annotated with the javax.jws.WebService annotation. The WebService annotation defines the class as a web service endpoint. The following Java code shows a web service. The IDE will create most of this Java code for you.

import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;

public class Calculator {
    public String operation(@WebParam(name="param_name")
            String param) {
        // implement the web service operation here
        return param;

    public int add(@WebParam(name = "i") int i,
           @WebParam(name = "j") int j) {
        int k = i + j;
        return k;

Notice that this web service performs a very simple operation. It takes two integers, adds them, and returns the result.

ProcedureTo Create the Web Service

Perform the following steps to use the IDE to create this web service.

  1. Click the Runtime tab in the left pane and verify that GlassFish is listed in the left pane. If it is not listed, register it by following the steps in Registering GlassFish with the IDE.

  2. Choose File->New Project, select Web Application from the Web category, and click Next.

  3. Assign the project a name that is representative of services that will be provided by the web service (for example, CalculatorApplication), set the Project Location to the location of the Sun application server, and click Finish.

    Note –

    When you create the web service project, be sure to define a Project Location that does not include spaces in the directory name. Spaces in the directory might cause the web service and web service clients to fail to build and deploy properly. To avoid this problem, Sun recommends that you create a directory, for example C:\work, and put your project there.

  4. Right-click the CalculatorApplication node and choose New->Web Service.

  5. Type the web service name (CalculatorWS) and the package name ( in the Web Service Name and the Package fields respectively.

  6. Select Create an Empty Web Service and click Finish.

    The IDE then creates a skeleton file for the web service that includes an empty WebService class with annotation @Webservice.

  7. Right-click within the body of the class and choose Web Service->Add Operation.

  8. In the upper part of the Add Operation dialog box, type add in Name and choose int from the Return Type drop-down list.

  9. In the lower part of the Add Operation dialog box, click Add and create a parameter of type int named i. Click OK. Click Add again and create a parameter of type int called j. Click OK and close the Enter Method Parameter dialog box.

  10. Click OK at the bottom of the Add Operation dialog box.

  11. Notice that the add method has been added to the Source Editor:

    public int add(@WebParam(name = "i") int i, @WebParam(name = "j") int j) {
        // TODO implement operation
        return 0;
  12. Change the add method to the following (changes are in bold):

    public int add(@WebParam(name = "i") int i, @WebParam(name = "j") int j) {
        int k = i + j;
        return k;

    Note –

    To ensure interoperability with Windows Communication Foundation (WCF) clients, you must specify the action element of @WebMethod in your endpoint implementation classes. WCF clients will incorrectly generate an empty string for the Action header if you do not specify the action element.

  13. Save the file.