Java Reference
In-Depth Information
And be very upset if the result is not 4! But yes, it really is possible to have a complete
SOAP client in two lines of Java, given the fact that the arguments are primitives and given
all the other work that wsimport and the toolkit have done for us:
// no imports!
/** Two-line client for Calc Service, complete code. */
public
public class
class TinyClientMain
TinyClientMain {
public
public static
void main ( String [] args ) {
Calc client = new
static void
new CalcService (). getCalcPort ();
System . out . println ( client . add ( 2 , 2 ));
}
}
$ java -cp target/classes jaxwsclient.TinyClientMain
4
$
The actual client in the jaxwsclient package provides an interactive calculator that lets you
input lines like 2 + 2 and get the answer:
$ java -cp target/classes jaxwsclient.ClientMain
Interactive calculator. Put spaces around operators.
>> 2 + 2
2 + 2 = 4
>> 22 / 7
22 / 7 = 3
>> ^D
$
Brilliant, eh? Incidentally, there is both a unit test in the service package and an integration
test (which just uses the static Endpoint.publish() to start and stop the service) in the cli-
ent package.
To recap, we did the following:
1. Created the service (but usually that will already be done for you).
2. Got the WSDL from the service with endpoint via “the ?wsdl trick”.
3. Ran the WSDL through wsimport to generate the client artifacts.
Search WWH ::




Custom Search