Your First Web Service

To get started with web services, we will create a simple “Hello World” web service that prints out a friendly message.

  1. Open the NetBeans IDE.
  2. Create a new project by choosing New → Project from the File menu to open the New Project Wizard dialog. In the dialog, choose Web from the category list on the left and choose Web Application from the Project list on the right. Click the Next button to continue.

  1. Enter a name for the web project and click Next to continue.

  1. Accept the defaults on the next dialog box and click Finish to create the project.
  2. Right-click on the project node and choose New → Web Service from the context menu.

  1. Name your web service HelloService and assign a package name. Click Finish to create the web service.

  1. A new node named Web Services appears under the web project and HelloService.java appears in the Editor pane. The Editor pane has a design view (the default view) and a source view. Click the source button at the top of the Editor pane to view the code.

  1. Click the Design button at the top of the Editor pane to switch back to the Design view.

  1. Click the Add Operation button in the upper left portion of the Design view.
  1. In the Add Operation wizard, change the name to sayHello and click OK to create the operation.
  1. Click on the Source button at the top of the Editor pane to switch to the source code.
  2. Edit the sayHello method and replace the default return statement to return the String “Hello! Welcome to the wonderful world of Web Services!”
  3. Click the Run button to start GlassFish. Additionally, you may need to choose Clean and Build Main Project from the Build menu or use the keyboard shortcut SHIFT + F11 to deploy the project to the web container.
  1. Expand the Web Services node in the project and right-click the HelloService web service. Choose Test Web Service from the context menu to test the web service you just created.
  1. Your web browser should automatically open to the web service tester. If it does not, open your favorite web browser and point it to
  2. Click the sayHello button to view the results of your web service.