Java Reference
In-Depth Information
Generating the client artifacts, and writing the client
Well, now we can get back to generating the client code. wsimport reads the WSDL, either
from the URL or from a file, and generates a whole pile of “artifacts”:
$ mkdir jaxwsclient
$ wsimport -d jaxwsclient -keep 'http://localhost:9090/calc?wsdl'
parsing WSDL...
Generating code...
Compiling code...
$ ls jaxwsclient/service/toy/*.java
Add.java Divide.java ObjectFactory.java
AddResponse.java DivideResponse.java Subtract.java
Calc.java Multiply.java SubtractResponse.java
CalcService.java MultiplyResponse.java package-info.java
$
You need to examine the generated Calc and CalcService files (there are copies in the
javasrcee repository in the jaxwsclient folder if you aren't building this as you go along; the
copies in the repository were moved to a shorter-named package but should be otherwise
identical). For a service with object arguments, you might have to examine the other gener-
ated artifacts, because there will be artifacts for the actual types the client has to pass into the
stub. Examining CalcService will tell you the method name you need to create a connec-
tion to the service—in our case:
// First Half of jaxwsclient.TinyClientMain
Calc client = new
new CalcService (). getCalcPort ();
Examining Calc will tell you the arguments you need to the Calc interface—at this point
you are supposed to pretend you've never seen the server-side version, and be particularly
careful not to import anything from the server-side package! We can now write code like
this:
// Second Half of jaxwsclient.TinyClientMain
System . out . println ( client . add ( 2 , 2 ));
Search WWH ::




Custom Search