background image

Coding the Service Endpoint

<< Requirements of a JAX-WS Endpoint | Deploying the ServiceUsing Ant >>
<< Requirements of a JAX-WS Endpoint | Deploying the ServiceUsing Ant >>

Coding the Service Endpoint

The implementing class must not define the finalize method.
The implementing class may use the javax.annotation.PostConstruct or
javax.annotation.PreDestroy
annotations on its methods for life cycle event callbacks.
The @PostConstruct method is called by the container before the implementing class
begins responding to web service clients.
The @PreDestroy method is called by the container before the endpoint is removed from
operation.
Coding the Service Endpoint Implementation Class
In this example, the implementation class, Hello, is annotated as a web service endpoint using
the @WebService annotation. Hello declares a single method named sayHello, annotated with
the @WebMethod annotation. @WebMethod exposes the annotated method to web service clients.
sayHello
returns a greeting to the client, using the name passed to sayHello to compose the
greeting. The implementation class also must define a default, public, no-argument
constructor.
package helloservice.endpoint;
import javax.jws.WebService;
@WebService
public class Hello {
private String message = new String(
"Hello, ");
public void Hello() {}
@WebMethod
public String sayHello(String name) {
return message + name +
".";
}
}
Building, Packaging, and Deploying the Service
You can build, package, and deploy the helloservice application using either NetBeans IDE or
ant
.
Building, Packaging, and Deploying the Service Using NetBeans IDE
Follow these instructions to build, package, and deploy the helloservice example to your
Application Server instance using the NetBeans IDE IDE.
1. In NetBeans IDE, select File
Open Project.
Creating a Simple Web Service and Client with JAX-WS
The Java EE 5 Tutorial · September 2007
482