Next, create the implementation class. Select File | New File. In New File, select Java in Categories and Java Class in File Types, and click on Next:
Specify the Class Name (HelloWSImpl), Package (hellows), and click on Finish:
The web service implementation class HelloWSImpl
is annotated with the @WebService
annotation and implements the HelloWS
interface. The implementation class contains a method hello
that takes a String
parameter for name and returns a Hello message containing the name. The implementation class is listed as follows:
package hellows; import javax.jws.*; @WebService(portName = "HelloWSPort", serviceName = "HelloWSService", targetNamespace = "http://hellows/", endpointInterface = "hellows.HelloWS") public class HelloWSImpl implements HelloWS { public String hello(String name) { // replace with your impl here return "Hello "+name +" Welcome to Web Services!"; } }
Similarly, add a Java interface for a SEI. The SEI declares public
methods that clients may invoke on the service. The SEI is optional, as a web service implementation class implicitly defines a SEI. As we specified, an explicit SEI with an endpointInterface
element in the @WebService
annotation in the implementation class, we must include a SEI with public
methods made available on the service. The service endpoint interface HelloWS
contains the hello
method annotated with the @WebMethod
annotation:
package hellows; import javax.jws.WebMethod; import javax.jws.WebService; @WebService(name = "HelloWS", targetNamespace = "http://hellows/") public interface HelloWS { @WebMethod(operationName = "hello") public String hello(String name); }
The implementation class and the endpoint interface are shown in the following NetBeans project: