JAX-WS Web Services in NetBeans 6.1

Java API for XML Web Services(JAX-WS) is an important part of latest JEE specification (Java EE 5 platform). In this article we will see how to develop JAX-WS based web services using NetBeans 6.1 IDE. This article will not provide any of the theoretical information about JAX-WS.

Software used

  • NetBeans 6.1
  • Java 5.0/6.0
  • GlassFish V2

Creating a Web project in NetBeans 6.1

To start with first of all we will have to create a web application from the web category. Let us name the project as “MyJaxWSApplication”. To create a create a web application we will do the following.

also read:

1. Choose File > New Project. Select Web Application from the Web category. Name the project as “MyJaxWSApplication” and click on Next.

2. In Server and Settings select the server that you want to use. Here we are going to use GlassFish.

3. Click Next and Finish.

Now its time to create web service form Java class

Creating Web Service project in NetBeans 6.1

  • Select the project you created and right click on the project node.
  • Choose New > Web Service.
  • A New Web service dialog window will open. Give the web service name as “Adder”, give the package name as “ws”. Make sure Create web service from scrach option is selected. Click on finish.
  • Web Services node will get created in projects window. Web Services node will contain a Adder node indicating the new web service we created just now. In the editor window area visual designer will open up as shown below.
  • Click Add Operation in the visual designer. A dialog box appears where you can define the new operation. In the dialog box enter the name of the service as “Add2Numbers” set the return type to “int”, then add two parameters. name the parameters as “number1” and “number2” select the type of both the parameters as “int”. Then click on OK
  • The designer now displays the following:
  • Now see the source genarated by the IDE by clicking on source tab in the visual designer. The IDE will generate the following source for you.
  • package ws;
    import javax.jws.WebMethod;
    import javax.jws.WebParam;
    import javax.jws.WebService;
    * @author Sri hari
    public class Adder {
     * Web service operation
    @WebMethod(operationName = "Add2Numbers")
    public int Add2Numbers(@WebParam(name = "number1")
    int number1, @WebParam(name = "number2")
    int number2) {
    	//TODO write your implementation code here:
    	return 0;
  • Now change the Add2Numbers method like the following, So that our operation will simply add two numbers and return the result.
  • /**
     * Web service operation
    @WebMethod(operationName = "Add2Numbers")
    public int Add2Numbers(@WebParam(name = "number1")
    int number1, @WebParam(name = "number2")
    int number2) {
    	return number1 + number2;
  • Now we successfully developed a web service wich will add two numbers.

Web Service Deployment in NetBeans 6.1

Now we will deploy the web service like below:

  • Right click the project node and select Undeploy and Deploy.
  • Once you do that IDE will start the server (GlassFish) and deploys the application to the server.

Web Service Testing in NetBeans 6.1

Now its time to test the web service.

In the IDE’s Projects tab, expand the Web Services node of the project. Right-click the services node, and choose Test Web Service. (Applicable only when deployed using GlassFish). AdderService Web Service Tester page shown below will open in the browser.

Enter the integer values in the textbox of the test page and click on add2Numbers button. This will lead to the result page as shown below.


In this article you have learnt how to develop a web service using Netbeans 6.1 and deploy the service in GlassFish application server. This article doesnot cover the creation of stubs using Netbeans 6.1 IDE. There are many ways to create stubs to test the web service. So keep learning. This is not the end, Still miles to go.

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This

Share this post with your friends!