WSDL Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 2.01

rpc/encoded Example - Get Exchange Rate

This section provides a tutorial example on writing a WSDL 1.1 example that uses SOAP 1.1 over HTTP with rpc/encoded as the message style and the encoding option.

"rpc/encoded" is the popular combination of message style and encoding option for most RPC (Remote Procedure Call) Web services. So let's write the second example with:

  • Location: http://www.herongyang.com/service/ GetExchangeRate_WSDL_11_SOAP_11_RPC.wsdl.
  • WSDL Version: 1.1
  • WSDL Binding Extension: SOAP 1.1
  • Transportation: SOAP 1.1 over HTTP
  • Message Style: rpc/encoded
  • encodingStyle: not provided

In this WSDL example, I want to send a SOAP request to call a RPC function to get an exchange rate. The function expects 3 input positional parameters and returns 1 value. So I wrote this WSDL document,

<?xml version="1.0"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:hy="http://www.herongyang.com/Service/"
  targetNamespace="http://www.herongyang.com/Service/">

  <wsdl:documentation>
    GetExchangeRate_WSDL_11_SOAP_11_RPC.wsdl
    Copyright (c) 2007 by Dr. Herong Yang, herongyang.com
    All rights reserved
  </wsdl:documentation>

  <wsdl:message name="getExchangeRateInputMessage">
    <wsdl:part name="datePart" type="xsd:date"/>
    <wsdl:part name="fromCurrencyPart" type="xsd:string"/>
    <wsdl:part name="toCurrencyPart" type="xsd:string"/>
  </wsdl:message>
  <wsdl:message name="getExchangeRateOutputMessage">
    <wsdl:part name="ratePart" type="xsd:decimal"/>
  </wsdl:message>

  <wsdl:portType name="getExchangeRatePortType">
    <wsdl:operation name="GetExchangeRate">
      <wsdl:input name="getExchangeRateInput"
        message="hy:getExchangeRateInputMessage"/>
      <wsdl:output name="getExchangeRateOutput"
        message="hy:getExchangeRateOutputMessage"/>
    </wsdl:operation>
  </wsdl:portType>

  <wsdl:binding name="getExchangeRateBinding"
    type="hy:getExchangeRatePortType">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="GetExchangeRate">
      <soap:operation style="rpc"
soapAction="http://www.herongyang.com/Service/getExchangeRate"/>
      <wsdl:input name="getExchangeRateInput">
        <soap:body use="encoded"
          parts="fromCurrencyPart toCurrencyPart datePart"/>
      </wsdl:input>
      <wsdl:output name="getExchangeRateOutput">
        <soap:body use="encoded" parts="ratePart"/>        
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>

  <wsdl:service name="getExchangeRateService">
    <wsdl:port name="getExchangeRatePort"
      binding="hy:getExchangeRateBinding">
      <soap:address location=
        "http://www.herongyang.com/Service/GetExchangeRate.php"/>
    </wsdl:port>
  </wsdl:service>

</wsdl:definitions>

Note that:

  • My input message is defined with multiple parts. Each part is used as one parameter for the RPC function.
  • Each input parameter is defined with an XML Schema built-in type. No explicit type definitions are used.
  • parts="fromCurrencyPart toCurrencyPart datePart" attribute is used with soap:body to set the order of input parameters.

See next section for testing requests and responses.

Last update: 2007.

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

 SOAP 1.1 Message Styles and Encoding Options

 First Example - Hello

 Request and Response - Hello

 document/literal Example - Guest Registration

 Request and Response - Guest Registration

rpc/encoded Example - Get Exchange Rate

 Request and Response - Get Exchange Rate

 SOAP Body and Operation Name - Book Reservation

 Request and Response - Book Reservation

 elementFormDefault="qualified" - Refill Order

 Request and Response - Refill Order

 encodingStyle="uri" for use="encoded"

 Request and Response - Get Stock Price

 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

 WSDL Related Terminologies

 References

 PDF Printing Version

Dr. Herong Yang, updated in 2013
rpc/encoded Example - Get Exchange Rate