Calling an RPC Method Based Web Service

This section provides a tutorial example on how to write a PHP program to call an RPC method based Web service using the SoapClient class.

Ok, let's try to use the SoapClient class to call my RPC Web service, GetExchangeRate_WSDL_11_SOAP_11_RPC.wsdl, first.

Here is the example PHP program, GetExchangeRate_Client.php:

# GetExchangeRate_Client.php
# Copyright (c) 2007 All Rights Reserved.
#- Loading the WSDL document
   $server = "";
   $wsdl = $server . "GetExchangeRate_WSDL_11_SOAP_11_RPC.wsdl";
   $client = new SoapClient($wsdl);

#- Calling the RPC method
   $result = $client->GetExchangeRate('USD', 'JPY', '2007-07-07');

#- Showing the result
   print "Exchange rate is: $result\n";

Execution result of this example is presented below:

herong> \local\php\php GetExchangeRate_Client.php

PHP Fatal error:  SOAP-ERROR: Parsing WSDL: Unspecified encodingStyle
   in C:\herong\GetExchangeRate_Client.php on line 8
Stack trace:
#0 C:\herong\GetExchangeRate_Client.php(8):
#1 {main} thrown in C:\herong\GetExchangeRate_Client.php on line 8

What's wrong here? The error message says, encodingStyle is not specified. Let's review the WSDL document:

  <wsdl:binding name="getExchangeRateBinding"
    <soap:binding transport=""/>
    <wsdl:operation name="GetExchangeRate">
      <soap:operation style="rpc"
      <wsdl:input name="getExchangeRateInput">
        <soap:body use="encoded"
          parts="fromCurrencyPart toCurrencyPart datePart"/>
      <wsdl:output name="getExchangeRateOutput">
        <soap:body use="encoded" parts="ratePart"/>

The root cause of the problem is in <soap body ...> elements. I did not provide the encodingStyle="uri" attribute. The error above tells us that the SoapClient class needs encodingStyle="uri" if use="encoded" is used.

To fix the WSDL document is easy, just add encodingStyle="" in <soap body ...> elements. But I am not going to fix it and keep it as is for testing purpose.

Conclusion, SoapClient class requires encodingStyle="uri", if use="encoded" is used. SoapClient class does not provide any default value to encodingStyle.

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

 Testing SOAP Extension with WSDL 1.1

 Methods on the SoapClient Class

Calling an RPC Method Based Web Service

 encodingStyle="uri" Required for rpc/encoded

 SoapParam Constructor - Creating Named Parameters

 SoapVar Constructor - Creating Encoded Values

 XSD_ANYXML Encoding - Building SOAP Body Element

 Calling an XML Document Based Web Service

 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

 Python SOAP Client: Zeep

 WSDL Related Terminologies

 Archived Tutorials


 Full Version in PDF/EPUB