WSDL Tutorials - Herong's Tutorial Examples - Version 2.03, by Dr. Herong Yang
RPC Method Based Web Service Example
This section provides a tutorial example on how to use stub and data type classes generated by WSDL2Java to invoke an RPC method based Web service.
After tested the stub class for an XML document based Web service, I want to test the stub class for an RPC method based Web service.
The WSDL document is located at http://www.herongyang.com/Service/ GetExchangeRate_WSDL_11_SOAP_11_RPC.wsdl, which defines is an RPC method based Web service with multiple input parameters.
Step 1 is to generate stub and data type classes using WSDL2Java:
C:\herong>\local\axis2\bin\wsdl2java -uri http://www.herongyang.com /Service/GetExchangeRate_WSDL_11_SOAP_11_RPC.wsdl -o axis2 -d adb -s
Step 2 is to write a test program in the .\axis2\src folder:
C:\herong>cd axis2\src C:\herong\axis2\src>type Axis2StubGetExchangeRate.java /** * Axis2StubGetExchangeRate.java * Copyright (c) 2009 by Dr. Herong Yang, herongyang.com * All rights reserved */ import java.io.*; import java.util.*; import com.herongyang.www.service.*; import com.herongyang.www.service.GetExchangeRateServiceStub.*; import org.apache.axis2.transport.http.*; class Axis2StubGetExchangeRate { public static void main(String[] args) { PrintStream out = System.out; try { // Creating the stub GetExchangeRateServiceStub stub = new GetExchangeRateServiceStub(); // Fixing org.apache.axis2.AxisFault: Transport error: // 411 Error: Length Required stub._getServiceClient().getOptions() .setProperty(HTTPConstants.CHUNKED,false); // Building the input parameter GetExchangeRate request = new GetExchangeRate(); request.setFromCurrencyPart("USD"); request.setToCurrencyPart("JPY"); request.setDatePart(new Date()); // Calling the operation GetExchangeRateResponse response = stub.GetExchangeRate(request); // Retrieving output parameter java.math.BigDecimal rate = response.getRatePart(); out.println(rate); } catch (Exception e) { e.printStackTrace(); } } }
Step 3 is to compile and run the test program:
C:\herong\\axis2\src>\local\jdk\bin\javac -Djava.ext.dirs=\local\axis2\lib\ com\herongyang\www\service\Axis2StubGetExchangeRate.java C:\herong\axis2\src>\local\jdk\bin\javac -Djava.ext.dirs=\local\axis2\lib\ Axis2StubRegistration.java C:\herong\axis2\src>\local\jdk\bin\java -Djava.ext.dirs=\local\axis2\lib\ Axis2StubGetExchangeRate 123.14
Cool. This proves that WSDL2Java supports RPC method based Web services correctly.
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
►Using WSDL2Java to Generate Web Service Stub Classes
Generating Client Side Stub Java Code
Using Stub and Data Type Classes
XML Document Based Web Service Example
"Unexpected subelement ..." Error from the Stub Class
►RPC Method Based Web Service Example
WSDL 1.1 Binding Extension for SOAP 1.2
WSDL 1.1 and SOAP 1.2 Examples - Document and RPC Styles