WSDL Tutorials - Herong's Tutorial Examples - v2.22, by Herong Yang
Archived: 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 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.
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
Using WSDL Document in Java Apache Axis2/Java for WSDL
Apache Woden for WSDL Documents in Java
SoapUI - Web Service Testing Tool
WSDL 1.1 Document Structure and Syntax
WSDL 1.1 Binding Extension for SOAP 1.1
SoapUI as WSDL 1.1 Testing Tool
WSDL 1.1 and SOAP 1.1 Examples - Document and RPC Styles
PHP SOAP Extension for WSDL 1.1
Apache Axis2/Java for WSDL 1.1
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
SOAP 1.2 Binding - PHP, Java and Perl Clients
Archived: Downloading and Installing SoapUI 3.0.1
Archived: SoapUI 3.0.1 MockService - Web Service Simulator
Archived: Downloading and Installing PHP 5.3.1
Archived: Downloading and Installing Axis2/Java 1.4.1
►Archived: Axis2GetSpeechClient.java - document/literal Style