Java Reference
In-Depth Information
}
}
TempVerterClient
first creates a
java.net.URL
instance that identifies the
web service's WSDL file. It then creates a
javax.xml.namespace.QName
in-
stance that identifies the endpoint's qualified service name (see
Figure 11-6
). These
instances are passed to the
javax.xml.ws.Service
class's
Service cre-
ate(URL wsdlDocumentLocation, QName serviceName)
classmethodto
return a
Service
instance that provides a client view of a web service.
Service
's
T getPort(QName portName, Class<T> serviceEnd-
pointInterface)
method is then called on the
Service
instance to return a
proxy for communicating with the web service via its endpoint. The qualified name
whichidentifiesthewebserviceinterfacewhoseoperationsaretobeaccessed—there
is only one interface in this example. The
java.lang.Class
instance passed to
serviceEndpointInterface
identifiesthe
TempVerter
SEI.Thismethodre-
turns a proxy object whose class implements
TempVerter
, or throws
javax.xml.ws.WebServiceException
when something goes wrong (such as
whennotspecifying
endpointInterface
inthe
TempVerterImpl
SIB's
@We-
bService
annotation, and calling
Service
's
T getPort(Class<T> ser-
viceEndpointInterface)
method, which uses
endpointInterface
to ac-
cess the SEI).
Assuming that
getPort()
succeeds, the returned object is used to invoke the
c2f()
and
f2c()
methodswithargumentsrepresentingbodytemperatureindegrees
Celsius and the boiling point of water in degrees Fahrenheit, respectively.
Compilethisclass(via
javac TempVerterClient.java
,whichassumesthat
the current directory contains this source file anda
ca
subdirectory,containing a
tu-
pVerter.java
sourcefile).Ifcompilationsucceeds,execute
java TempVerter-
Client
to run this application, which should generate the following output:
98.6
100.0
Because the WSDL document in
Listing 11-5
and the XML Schema document in
Listing 11-6
contain enough information to let clients communicate with the web ser-
vice,youcanalternativelyusethe
wsimport
tooltogenerateclient-supportcodefrom