Java Reference
In-Depth Information
using the WSDLDriverFactory class, pointing to the calculator service WSDL. You then in-
dicate that you want to dump to the standard error output stream the contents of the SOAP
messages destined for the service.
Next, invoke the service. The add operation is defined on the calculator WSDL. You set the
values of i and j , also defined as the parameter names on the WSDL, to 6 and 9 respectively.
The value returned by the service is stored in the result variable. You call puts to print the
string containing the message and the result to the console. The string in this case is similar to
how you would use the String.format feature added in Java SE 5. To get the sum, you need
to drill down to the value of the return element in the SOAP response.
Running this in the Ruby interpreter prints the complete SOAP request and response to the
console (as a result of the wire dump), and then shows the result:
Result is 15!
Despite the fact that this is a document/literal wrapped web service, the call to cre-
ate_rpc_driver works just fine. The interesting line of code is this one:
"#{result.return}"
Java web services, if left to their default mapping (with no @WebResult annotation), will en-
close their wrapped results in an element called <return> , which is a keyword in Ruby. You
need to inspect the returned XML document to get to the value that you're interested in here.
But you don't need to do extensive XPath-type drilling down through each element as you
might with the SAAJ library. You can just indicate which element's value you want from the
SOAP response using that syntax.
So you have to use a Ruby feature called interpolation, which inserts a string into a literal and
evaluates the call. If you just tried to print the result directly, you'd see something like this:
Result is #<SOAP::Mapping::Object:0x2802094>!
That's because while you're getting a SOAP mapping object returned, it's printing something
similar to what you get in Java if you don't override the toString method. So the wire dump
would still show the contents of the entire SOAP response, but if you want to do some actual
work with the values buried within the response, you need to do this.
The result is printed to the console using a C-style formatter that is similar to the functionality
added to Java SE 5.
Search WWH ::




Custom Search