background image

A Simple JAX-WS Client

<< Testing the Service Without a Client | Types Supported by JAX-WS >>
<< Testing the Service Without a Client | Types Supported by JAX-WS >>
xxii
B
UILDING
W
EB
S
ERVICES WITH
JAX-WS
@WebServiceRef(wsdlLocation="http://localhost:8080/
helloservice/hello?wsdl")
static HelloService service;
2. Retrieves a proxy to the service, also known as a port, by invoking
getH-
elloPort
on the service.
Hello port = service.getHelloPort();
The port implements the SEI defined by the service.
3. Invokes the port's sayHello method, passing to the service a name.
String response = port.sayHello(name);
Here's
the
full
source
of
HelloClient,
located
in
the
<INSTALL>/javaeetutorial5/examples/jaxws/simpleclient/src/
direc-
tory.
package simpleclient;
import javax.xml.ws.WebServiceRef;
import helloservice.endpoint.HelloService;
import helloservice.endpoint.Hello;
public class HelloClient {
@WebServiceRef(wsdlLocation="http://localhost:8080/
helloservice/hello?wsdl")
static HelloService service;
public static void main(String[] args) {
try {
HelloClient client = new HelloClient();
client.doTest(args);
} catch(Exception e) {
e.printStackTrace();
}
}
public void doTest(String[] args) {
try {
System.out.println("Retrieving the port from
the following service: " + service);
Hello port = service.getHelloPort();
System.out.println("Invoking the sayHello operation
on the port.");
String name;
if (args.length > 0) {
name = args[0];
} else {