Back to Web Services Resources and Tutorials
Generating a Client with wscompileHere, we will use Sun's wscompile utility to generate a client stub and supporting classes and write a short test program to invoke a web service. By now, you should have already created the src/client directory under the tutorial's top-level directory. From the top-level directory, execute the following:
wscompile -gen:client -keep -d src/client -f:documentliteral,wsi config.xmlAs with the server-side option, wscompile also compiles the source files. In addition to creating the bean classes and the remote interface, the client option generates serializer classes, a Service interface, and an implementation of the Service interface. We will write a client which uses the Service implementation to access the web service.
In the src/client/com/example directory, create a client application; an example can be found at TutorialClient.java. Briefly, the client takes as command-line arguments the endpoint URL of the web service (this will allow us to pass in a different endpoint so we can debug later if necessary) and the message of the ping request. The client then instantiates a Service object, retrieves a stub from it, sets the endpoint property of the stub, and then makes the ping request, printing out information along the way.
From the src/client directory, substituting as necessary for your specific paths, execute the following command:
javac -cp C:/Sun/AppServer/lib/jaxrpc-api.jar;C:/Sun/AppServer/lib/jaxrpc-impl.jar com/example/*.javaThis will leave all the compiled .class files in the src/client structure, which is fine for the purposes of this tutorial.
Test the web service with the following command line:
java -cp C:/Sun/AppServer/lib/jaxrpc-api.jar;C:/Sun/AppServer/lib/jaxrpc-impl.jar;. com.example.TutorialClient endpointURL Pingwhere the endpoint URL would be as follows for the tutorial web services created earlier:
http://localhost:8080/jboss-net/services/TutorialService_Port
http://localhost:8080/tutorial/ping
Ping request string is 'Ping' Response string is 'This is the response to request 'Ping''Note that the wscompile-produced stub works on the JBoss 3.2.7 web service, despite the fact that the JBoss-3.2.7/Axis WSDL2Java-produced stub does not. This is a reflection of the loose coupling that makes web services attractive: as long as the request arrives in the right format, in this case SOAP over HTTP, with the expected request document, the web service implementation does not care how it was generated.