You are on page 1of 2

Web Service

Aim:

To create and invoke a Web service using Glassfish in NetBeans.

Procedure:

Step 1: Create project


Open Netbeans >> Select File >> New Project >> Java Web: Web Application
Click Next >> Enter Project name: HelloWorldWebService:
Click Next >> Select Server:
Click Finish

Step 2: Create WebService

Right click on the project HelloWorldWebService >> New >> Web Service:
Enter Web service name: SayHelloService
Enter Package: com.prgguru.example
Click Finish

Step 3: Add/Update web method

Step 4: Clean and build the application

Right click on the project, select Clean and Build.

Step 5: Deploy the application

Right click on the project, select Deploy.

Step 6: Test the webservice

Right click on the web service SayHelloService and select Test Web Service.
It will open up the browser where the service we created can be tested
Enter the name in the textbox and hit hello button, you could see the response from the server
as shown below:
Index.html

<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form name="f1" method="get" action="SayHelloapp">
<input type="text" name="nm">
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

Webservice:
SayHelloService.java:

package com.hello1.example;

import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;

/**
*
* @author Student
*/
@WebService(serviceName = "SayHelloapp")
public class SayHelloapp {

/**
* This is a sample web service operation
*/
@WebMethod(operationName = "hello")
public String hello12(@WebParam(name = "name") String txt) {
return "Hello " + txt + " !";
}
}

Result:

Thus the Web service program using Glassfish in Net Beans was created successfully.

You might also like