The WSIT Tutorial

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 (org.me.calculator) 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 CalculatorWS.java 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:

    @WebMethod
    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):

    @WebMethod(action="add")
    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 CalculatorWS.java file.