To create and execute SOAP-based web service program using server, client and client- side remote invocation.
Open NetBeans IDE.
Click File->New Project. Choose Java Web and then Web Application and click Next.
Give your Project a suitable Name and then click Next.
In the next window, make sure you have selected Server as “GlassFish Server” and Java EE Version as “Java EE 7 Web”. Click Finish.
Your new project will appear in the Projects tab in the left-most part of NetBeans.
Right click your Project and select New->Web-Service.
In the new window, give your web service a name and a package name. Click Finish.
A new coding tab will open that contains your web service.
Expand the folder “Web Services” under your project. You should see your newly created web service. Right-click on it and choose “Add Operation”.
A new window to add operation will appear. In that give Name, Return Type to your operation. Then click the Add button to add necessary arguments/parameters for that
operation. (Since we are demonstrating simple addition, we use two arguments/parameters.) Once you are happy with your parameters/arguments, click OK.
NetBeans will automatically generate the skeleton for the operation which will be like,
. Replace return 0.0 with return (a+b)
Save your project. Right-click on the project, select “Clean and Build”. Once the Building process is successful, again Right-click on the project, select “Deploy”. Deploying might take time depending on the size of the project.
Once your project is successfully deployed, right-click on your web service name and select “Test Web Service”
A new browser window will appear which will look like this
You can give inputs to your web service and check whether it is working properly or not. If it is working properly, you will get a page like this
Create a new Java Web Project in NetBeans. (Follow Steps 1-5 as in section 1.1)
Right-click on the project and select New->Web Service Client.
A new window will appear. Select “Project” under the heading “Specify the WSDL file of the Web Service.” and click Browse
A new window will appear, in that carefully choose appropriate web service and click OK.
The Project file will be filled with the location to the WSDL file of the web service. If you prefer, you can give a package name. Or else click Finish
In the Output Window at the bottom of NetBeans, you can notice that the client gathers the operations available in the web service.
Once it is done, you should see “BUILD SUCCESSFUL”.
Right-click on “Web Pages” under your Project and select “JSP”.
A new window will appear, give a name to your jsp page and click Finish.
Expand the folder named “Web Service References”-> “Addition” “Addition” “AdditionPort”. Once expanded you should see all the operations available in your web service.
Carefully drag “add” operation and drop it into the JSP page. NetBeans will automatically create the code for invoking this operation which will be like,
Give values to your arguments and run the JSP file.
A new browser window with the output will appear.
Follow Step 1 and Step 2 as in Client-side (section 1.2).
A new window will appear. Select “WSDL URL” under the heading “Specify the WSDL file of the Web Service.” and type the URL of the web service’s WSDL file. (Typically, the URL of the form http://ip:8080/Proj_name/Webservice_name?wsdl)
The remaining procedure is the same as the Client-side.
Thus, the SOAP based addition program using Web service is executed successfully.