Java Reference
In-Depth Information
Working with SOAP-Based Web Services
JAX-WSsupportsSOAP-basedwebservices.Thissectionfirstshowsyouhowtocreate
and access your own SOAP-based temperature-conversion web service, publish this
webservicelocallyviathedefaultlightweightHTTPserver,andaccesstheservicevia
asimpleclient.ItthenshowsyouhowtoaccesstheSloanDigitalSkySurvey'sSOAP-
based image cutout web service to obtain astronomy images.
Creating and Accessing a Temperature-Conversion Web Service
The temperature-conversion web service, which I've named TempVerter, consists of a
pair of functions for converting degrees Fahrenheit to degrees Celsius and vice versa.
AlthoughthisexamplecouldbearchitectedasasingleJavaclass,I'vechosentofollow
bestpracticesbyarchitectingitasaJavainterfaceandaJavaclass. Listing11-2 presents
the web service's TempVerter interface.
Listing 11-2. TempVerter's Service Endpoint Interface
package ca.tutortutor.tv;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public interface TempVerter
{
@WebMethod double c2f(double degrees);
@WebMethod double f2c(double degrees);
}
TempVerter describesa Service Endpoint Interface (SEI) ,whichisaJavainterface
thatexposesawebserviceinterface'soperationsintermsofabstractJavamethods.Cli-
ents communicate with SOAP-based web services via their SEIs.
TempVerter isdeclaredtobeanSEIviathe @WebService annotation.Whena
Javainterfaceorclassisannotated @WebService ,all public methodswhosepara-
meters, return values, and declared exceptions follow the rules defined in Section 5
oftheJAX-RPC1.1specification( http://download.oracle.com/otndocs/
jcp/jax_rpc-1_1-mrel-oth-JSpec/ ) describe web service operations. Be-
causeonly public methodscanbedeclaredininterfaces,the public reservedword
Search WWH ::




Custom Search