9.3.3 Add Desired Operations to the Web Service
The goal of this service project is to add two integers received from a client via an operation. The NetBeans IDE 12.0 provides a dialog for adding an operation or a method to a Web service. You can open this dialog either in the Web service visual designer or in the Web service context menu.
To open this dialog using the Web service visual designer, perform the following operations:
• Open our Web service main file, WSTest.java, by double-clicking on it in the Projects window.
• Click on the Design button at the top of this window.
To open this dialog using the Web service context menu:
• Find our target Web service output file, WSTest, from the Web Services node in the
Projects window.
• Right-click on that node to open the context menu.
In the opened service designer, right-click on the default operation, hello, and select the Remove Operation item from the popup menu to remove this default operation, since we do not need it. Then click on Add Operation, and a dialog box appears to enable us to add and define a new operation. Perform these steps to add a new addition operation or method:
1) In the upper part of the Add Operation dialog box, type Add in the Name field and int in the Return Type drop-down list. In the lower part of the Add Operation dialog box, click on the Add button and create a parameter with a type int named Input1. Then click on the Add button again and create the second parameter with a type int called Input2. Your finished Add Operation dialog should match the one shown in Figure 9.9.
2) Click on the OK button to close this dialog. The new added operation is displayed in the visual designer, as shown in Figure 9.10.
3) Click on the Source button at the top of this window to open the code window of the Web service main body file, and you can see that our new Web operation or method Add() has been added into this class, as shown in Figure 9.11.
4) In the opened WebMethod Add(), enter this code into the method:
int result = Input1 + Input2;
return result;
At this point, we have finished developing our Web service project, and next we need to deploy it to the selected Web container and test it with some consuming projects.