Java Axis2 1.4.1 - XML Document Based Web Services

This section provides a tutorial example on how to write a Java program to call an RPC method based Web service with SOAP 1.2 binding using the RPCServiceClient class provided in Axis2 1.4.1.

According to the manual, Axis2 1.4.1 supports SOAP 1.2. So let me try Axis2 1.4.1 with my GetExchangeRate RPC method based Web service first.

Here is the example Java program, Axis2GetExchangeRateSoap12Client.java:

/**
 * Axis2GetExchangeRateSoap12Client.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.rpc.client.RPCServiceClient;
import org.apache.axis2.client.Options;
import org.apache.axis2.transport.http.HTTPConstants;
class Axis2GetExchangeRateSoap12Client {
   public static void main(String[] args) {
      PrintStream out = System.out;

// Setting initial values
      String wsdl = "http://www.herongyang.com/Service/";
      wsdl += "GetExchangeRate_WSDL_11_SOAP_12_RPC.wsdl";
      String tns = "http://www.herongyang.com/Service/";
      String serviceName = "getExchangeRateService";
      String portName = "getExchangeRatePort";

      try {
         RPCServiceClient client = new RPCServiceClient(null, 
            new URL(wsdl), new QName(tns, serviceName), portName);
         Options option = client.getOptions();
         option.setProperty(HTTPConstants.CHUNKED,false);

// Building the input parameter array
         Object[] inputArgs = new Object[3];
         inputArgs[0] = new String("USD");
         inputArgs[1] = new String("JPY");
         inputArgs[2] = new String("2007-07-07");

// Building the return value type array
         Class[] returnTypes = new Class[1];
         returnTypes[0] = Class.forName("java.lang.String");

// Invoking the Web service
         Object[] returnValues = client.invokeBlocking(
	    new QName(tns, "GetExchangeRate"),
	    inputArgs, returnTypes);

// Printing the return value
         out.println(returnValues[0]);

      } catch (Exception e) {
         e.printStackTrace(); 
      }
   }
}

Here is the result of this tutorial program:

C:\herong>\local\jdk\bin\javac -Djava.ext.dirs=\local\axis2\lib\
   Axis2GetExchangeRateSoap12Client.java

C:\herong>\local\jdk\bin\java -Djava.ext.dirs=\local\axis2\lib\
   Axis2GetExchangeRateSoap12Client

log4j:WARN No appenders could be found for logger (org.apache.axis2.description.
WSDL11ToAxisServiceBuilder).
log4j:WARN Please initialize the log4j system properly.

123.14

Cool. This confirms that Axis2 1.4.1 does support RPC method based Web services defined in WSDL 1.1 with SOAP 1.2 binding.

Last update: 2009.

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

 WSDL 20 Programming APIs and Testing Tools

 Introduction to WSDL 1.1

 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

 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

 PHP SOAP Extension - RPC Method Based Web Services

 PHP SOAP Extension - XML Document Based Web Services

Java Axis2 1.4.1 - XML Document Based Web Services

 Java Axis2 1.4.1 - RPC Method Based Web Services

 Perl SOAP::Lite 0.710 - No WSDL 1.1/SOAP 1.2 Support

 WSDL Related Terminologies

 References

 PDF Printing Version