Making your own SOAP Webservice with Netbeans IDE
Posted by Anurag Jain* Filled under keyword soap web service,web service,wsdl
This tutorial tells, how you can make your own simple Java SOAP webservice making use of a Netbeans IDE
After you complete this tutorial you will be able to make such simple webservices in hardly 5 mins.
First open your netbeans IDE.
Goto File--> New Project
Choose Java Web on left side and then choose Web Application on right side.
Give a name to this project for eg i would be using project name as AddService. Click on Next. Make sure in next screen you see an appropriate server, default is Glassfish server in netbeans.
Click on next and then finish.
Now click on the new Project made ie AddService and right click on it.
Goto New and then choose Webservice. If you dont see Webservice directly then goto New-->Other-->Webservices
Choose a name for this Webservice. I am giving the name as AddServiceWS and giving the package name as add.
Now a window will open named AddServiceWS.java
Now click on design tab.
Now click on Add operation which is used to add any new functionality.
Now you need to give a name for this service. I am giving this as Addoperation.
Since we are going to add number so our result will also be an integer so we keep return type as int
Now in Parameter tab click on Add.
Give the name as parm1, type of parameter is integer so we give as int
Since for addition we require 2 number so we again click on Add.
We give name as parm2,type as int
Click on OK
Goto Source tab.
Your method is now made. Currently it must be returning 0.
To make it return the addition we change it to return parm1+parm2;
So, finally we have made our web service. Now to use it we need to deploy it on the server.
For that just choose the project name ie AddService. Right click and choose Deploy.
After it complete deploying we can check the webservice using in built netbean tool.
Goto your project folder ie AddService then choose Webservices folder. Inside this you will get AddServiceWS.
Now right click on AddServiceWS and choose Test Webservice.
Your browser will open. Enter the 2 number and click on addoperation , it will return the addition
To distribute this service to your client you would require the WSDL file.
When you test your webservice your browser will open and URL would be like http://localhost:8080/AddService/AddServiceWSService?Tester.
Change ?Tester with ?WSDL to obtain the WSDL(http://localhost:8080/AddService/AddServiceWSService?WSDL)
Another simple way to get WSDL is just goto the AddServiceWS in project hierarchy and right click on it.
Choose Generate and Copy WSDL.It would ask the destination to save.
It would generate the WSDL and keep it in your netbeans project directory
In coming articles we will learn how call webservice using this wsdl, Making cool webservice like track my ip etc.Hope you liked it.. :)
Please login to add your comments