WSDL Tutorials - Herong's Tutorial Examples - Version 2.03, by Dr. Herong Yang
Axis2GetSpeechClient.java - document/literal Style
This section provides a tutorial example on how to build a SOAP Body message in document/literal style and call the GetSpeech Web service.
Writing a Web service client program using Axis2 seems to be very easy. Let's write another one, Axis2GetSpeechClient.java.
In this program, I used the WSDL document located at http://www.xmlme.com/WSShakespeare.asmx?WSDL. This Web services uses the document/literal message style.
/** * Axis2GetSpeechClient.java * Copyright (c) 2009 by Dr. Herong Yang, herongyang.com * All rights reserved */ import java.io.PrintStream; import java.net.URL; import javax.xml.namespace.QName; import org.apache.axis2.client.ServiceClient; import org.apache.axis2.client.Options; import org.apache.axis2.transport.http.HTTPConstants; import org.apache.axiom.om.*; class Axis2GetSpeechClient { public static void main(String[] args) { PrintStream out = System.out; // Setting initial values String wsdl = "http://www.xmlme.com/WSShakespeare.asmx?WSDL"; String tns = "http://xmlme.com/WebServices"; String serviceName = "Shakespeare"; String portName = "ShakespeareSoap"; try { ServiceClient client = new ServiceClient(null, new URL(wsdl), new QName(tns, serviceName), portName); Options option = client.getOptions(); option.setProperty(HTTPConstants.CHUNKED,false); // Building SOAP Body element for the request OMFactory factory = OMAbstractFactory.getOMFactory(); OMNamespace namespace = factory.createOMNamespace(tns, "tns"); OMElement request = factory.createOMElement( "GetSpeech", namespace); OMElement child = factory.createOMElement( "Request", namespace); child.setText("To be, or not to be"); request.addChild(child); // Printing the request as an XML string out.println(); out.println("Request XML message"); out.println(request); OMElement response = client.sendReceive( new QName(tns, "GetSpeech"), request); // Printing the response as an XML string out.println(); out.println("Response XML message"); out.println(response); } catch (Exception e) { e.printStackTrace(); } } }
Output of this program is presented below:
Request XML message <tns:GetSpeech xmlns:tns="http://xmlme.com/WebServices"> <tns:Request>To be, or not to be</tns:Request> </tns:GetSpeech> Response XML message <GetSpeechResponse xmlns="http://xmlme.com/WebServices"> <GetSpeechResult> <SPEECH> <PLAY>HAMLET</PLAY> <SPEAKER>HAMLET</SPEAKER> To be, or not to be: that is the question: Whether 'tis nobler ... </SPEECH> </GetSpeechResult> </GetSpeechResponse>
This test program shows that Axis2 supports WSDL 1.1 very well.
Last update: 2009.
Table of Contents
WSDL 2.0 Document Structure and Syntax
WSDL Version 2.0 Part 2: Adjuncts
WSDL 2.0 Document Examples with SOAP Binding
WSDL 20 Programming APIs and Testing Tools
WSDL 1.1 Document Structure and Syntax
WSDL 1.1 Binding Extension for SOAP 1.1
soapUI 3.0.1 - Web Service Testing Tool
WSDL 1.1 and SOAP 1.1 Examples - Document and RPC Styles
PHP SOAP Extension in PHP 5.3.1
Using WSDL in Perl with SOAP::Lite 0.710
►Using WSDL Document in Java with Axis2 1.4.1
Downloading and Installing Axis2/Java 1.4.1
org.apache.axis2.client.ServiceClient Class
Creating Service Client with WSDL Document
org.apache.axis2.client.Options - Operation Client Options
sendReceive() Method - Invoking a Named Operation
Turning Off the Chunked HTTP Flag
Axis2RegistrationClient.java - document/literal Style
►Axis2GetSpeechClient.java - document/literal Style
org.apache.axis2.rpc.client.RPCServiceClient Class
Axis2GetExchangeRateClient.java - rpc/encoded Style
SocketRequestResponseServer.java - Socket Server Testing Program
Capturing the HTTP Request from an Axis2 Client Program
Using WSDL2Java to Generate Web Service Stub Classes
WSDL 1.1 Binding Extension for SOAP 1.2
WSDL 1.1 and SOAP 1.2 Examples - Document and RPC Styles