background image

A Simple JAX-WS Client

<< Testing the Service without a Client | Building and Running the Client >>
<< Testing the Service without a Client | Building and Running the Client >>

A Simple JAX-WS Client

String response = port.sayHello(name);
Here is the full source of HelloClient, which is located in the
tut-install/javaeetutorial5/examples/jaxws/simpleclient/src/java/ directory.
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 {
name =
"No Name";
}
String response = port.sayHello(name);
System.out.println(response);
} catch(Exception e) {
e.printStackTrace();
}
}
}
Creating a Simple Web Service and Client with JAX-WS
Chapter 16 · Building Web Services with JAX-WS
485