Outdated: 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) 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();

// 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");

// Printing the request as an XML string
	 out.println("Request XML message");
         OMElement response = client.sendReceive(
	    new QName(tns, "GetSpeech"), request);

// Printing the response as an XML string
	 out.println("Response XML message");
      } catch (Exception e) {

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>

Response XML message
<GetSpeechResponse xmlns="http://xmlme.com/WebServices">
      To be, or not to be: that is the question: Whether 'tis nobler

This test program shows that Axis2 supports WSDL 1.1 very well.

Table of Contents

 About This Book

 Introduction to WSDL 2.0

 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

 PHP SOAP Extension for WSDL

 Perl SOAP::Lite for WSDL

 Introduction to WSDL 1.1

 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

 Perl SOAP::Lite 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

 WSDL Related Terminologies

Outdated Tutorials

 Outdated: Downloading and Installing SoapUI 3.0.1

 Outdated: SoapUI 3.0.1 MockService - Web Service Simulator

 Outdated: Downloading and Installing PHP 5.3.1

 Outdated: Downloading and Installing Axis2/Java 1.4.1

Outdated: Axis2GetSpeechClient.java - document/literal Style


 Full Version in PDF/EPUB