background image

Coding the Service Endpoint

<< Requirements of a JAX-WS Endpoint | Packaging and Deploying the Service >>
<< Requirements of a JAX-WS Endpoint | Packaging and Deploying the Service >>
C
ODING THE
S
ERVICE
E
NDPOINT
I
MPLEMENTATION
C
LASS
xix
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 greet-
ing to the client, using the name passed to
sayHello
to compose the greeting.
The implementation class also must define a default, public, no-argument con-
structor.
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 the Service
To
build
HelloService
,
in
a
terminal
window
go
to
the
<INSTALL>/javaeetutorial5/examples/jaxws/helloservice/
directory and
type the following:
asant build
The
build
task command executes these
asant
subtasks:
·
compile-service