Updated Java Web Services Message Client Redux now available.
Most of the Java web services examples on the web use an RPC-style interface. That’s fine when you’re calling a web service implemented in Java. But web services being what they are, you’ll eventually find yourself invoking a message-style web service whose WSDL gives wsdl2java fits.
When that time comes, you can either roll your own code rather than use wsdl2java or you can go with the flow with a message-style interface. I think that you’ll find it easier to go with the message-style interface. And to make it even easier, here is a simple message-style client to get you started.
This client reads an input document from standard input, invokes a web service, and then prints the web service response. The results shown here use Java 1.4.2_11 and Axis 1.3.
1 | import org.apache.axis.client.Call; |
And here is the client in action, calling the echoString operation of the echo web service example included in the Axis distribution. The actual response body is a single line, I have taken the liberty of formatting the response for easier reading.
1 | 12 $ javac -classpath $AXISCLASSPATH Simple.java 13 $ java -classpath $AXISCLASSPATH Simple < data/echo.xml <?xml version="1.0" standalone="yes" ?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://soapinterop.org/xsd"> <soap:Body> <ns1:echoString> <ns1:echoStringRequest>Hello World</ns1:echoStringRequest> </ns1:echoString> </soap:Body> </soap:Envelope> Invoking http://stephan-desktop/axis/services/echo <soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <ns2:echoStringResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://soapinterop.org/xsd"> <return xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Hello World</return> </ns2:echoStringResponse> </soapenv:Body> 14 $ |
Feb 9: Examining your Java app with a debugging proxy.
Sep 19: Java Web Services Message Client Redux.