Web Service

In this example program I will show you how you can make webservices in the Netbeans IDE.

Web Service

Web Services with NetBeans IDE


Creating webservices in NetBeans.

In this example program I will show you how you can make webservices in the Netbeans IDE. NetBeans IDE provides necessary GUI Tool to help the developers to quickly develop and deploy web services.

In this example we will

a) Develop webservices

b) Test the webservice

c) Develop client and call the webservice there

d) Finally deploy and test the application

Web Service can be added in a Web project or in Ejb project. Netbeans IDE helps the developers to easily develop and test the webservices. It’s easy to make the Web Service program in Netbeans, which has Glassfish server by default.

Web Service program in Web Project
In Netbeans take new web project in figure 1

Web Services Example
     Figure 1


Give project name   webservice1 as shown in figure 2  


Web Services Example
    Figure 2


Select the server name in figure 3

Web Services Example
     Figure 3


Now Rt Click on the Web Service project  in figure 4

Select New->WebService

Web Services Example

   Figure 4


Now give the name of the Web Service and package name  figure 5

Web Services Example
     Figure 5

Now In design view of Web Service  click on Add Operation  in figure 6

Web Services Example
    Figure 6

Here  give the operation name and parameter name and type as shown  in figure 7

Web Services Example 

     Figure 7      0


Now in source view change the return null to return “hello ”+name as in figure 8

Web Services Example 1

   Figure 8

Now Rt Click on the project and deploy it on the server  as in figure 9

Web Services Example
    Figure 9
It will deploy the war file on to the server
Now test the web service program
Rt click on the MyWebService in web services folder and select Test Web Operation as in figure 10 2

Web Services Example 

    Figure 10

It will open the Web Service  program in browser as in figure 11
Web Services Example 3

  Figure 11
Click on WSDL File in blue color .It will open the WSDL  file in the browser as in figure 12
Web Services Example
    Figure 12
Now as in fig type the roseindia in the text field and click on show button  as in figure 13

Web Services Example
    Figure 13


It will return hello roseindia
It also give the SOAP request and SOAP response  pf the Web Service  as in figure 14


Web Services Example
   Figure 14 5


Now make the client file.Client file can be java servlet , jsp  and standalone java file
Start a new web project as in figure 15.
Give project name as Webservice1-client

Web Services Example
Now Rt. Click on the project select NewàWeb Service client 6

Here  now select the WSDL file of the Web Service as in figure 15
Click on the Browse.

Web Services Example

Now select the webservice1àMyWebService
Web Services Example
     Figure 15 7

It creates the Client environments for the Web Service   in the given project
Now make a Client   file  by just taking a new Jsp file as in figure 16

Web Services Example
   Figure 16


Give the file name as client.jsp
Rt click  in client.jsp file code  and select  Web Service Client resources -->Call Web Service  Operation in figure 17


Web Services Example
    Figure 17 9

Select the web service project ->web service file->web service port->operation name  as in figure 18
Web Services Example

   Figure 18
Change   the name =”null”  to  name=”roseindia”  as in figure 19

Web Services Example
   Figure 19 0

Rt click in client.jsp and select run client.jsp

Web Services Example

Download Code 1