ptg7068951
316 HOUR 22:Creating Web Services with JAX-WS
Creating a Service Implementation
Bean
The Java class that implements the Service Endpoint Interface is called the
Service Implementation Bean. Learning odd new bits of jargon is an
unavoidable part of JAX-WS.
The SquareRootServerImplclass implements the SquareRootServerinter-
face, as stated in the class declaration:
public classSquareRootServerImpl implementsSquareRootServer {
This means the class you’re creating must contain all the methods in the
interface, each with the proper parameters.
The getSquareRoot(double)and getTime()methods are implemented
using techniques you’ve learned previously.
The only new aspect of the class is the following annotation, which appears
before the classstatement:
@WebService(endpointInterface = “com.java24hours.ws.SquareRootServer”)
This annotation indicates the class is a service implementation bean for a
service endpoint interface named com.java24hours.ws.SquareRootServer.
You must use the full class name, including the name of its package.
Take note of the fact that annotations are not followed by semicolons, unlike
statements.
Start coding this class: Create a new empty Java file named
SquareRootServerImplin the package com.java24hours.ws, and then fill it
with the contents of Listing 22.2.
LISTING 22.2 The Full Text of SquareRootServerImpl.java
1: packagecom.java24hours.ws;
2:
3: importjava.util.*;
4: importjavax.jws.*;
5:
6: @WebService(endpointInterface = “com.java24hours.ws.SquareRootServer”)
7:
8: public classSquareRootServerImpl implementsSquareRootServer {
9:
10: public doublegetSquareRoot(doubleinput) {
11: returnMath.sqrt(input);
12: }