background image

Testing the Service without a Client

<< Deploying the ServiceUsing Ant | A Simple JAX-WS Client >>
<< Deploying the ServiceUsing Ant | A Simple JAX-WS Client >>

Testing the Service without a Client

Testing the Service without a Client
The Application Server Admin Console allows you to test the methods of a web service
endpoint. To test the sayHello method of HelloService, do the following:
1. Open the Admin Console by typing the following URL in a web browser:
http://localhost:4848/
2. Enter the admin user name and password to log in to the Admin Console.
3. Click Web Services in the left pane of the Admin Console.
4. Click Hello.
5. Click Test.
6. Under Methods, enter a name as the parameter to the sayHello method.
7. Click the sayHello button.
This will take you to the sayHello Method invocation page.
8. Under Method returned, you'll see the response from the endpoint.
A Simple JAX-WS Client
HelloClient
is a stand-alone Java program that accesses the sayHello method of
HelloService
. It makes this call through a port, a local object that acts as a proxy for the remote
service. The port is created at development time by the wsimport tool, which generates JAX-WS
portable artifacts based on a WSDL file.
Coding the Client
When invoking the remote methods on the port, the client performs these steps:
1. Uses the javax.xml.ws.WebServiceRef annotation to declare a reference to a web service.
@WebServiceRef
uses the wsdlLocation element to specify the URI of the deployed service's
WSDL file.
@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 getHelloPort 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.
Creating a Simple Web Service and Client with JAX-WS
The Java EE 5 Tutorial · September 2007
484