PHP SOAP Extension - RPC Method Based Web Services

This section provides a tutorial example on how to write a PHP program to call an RPC method based Web service with SOAP 1.2 binding using the SoapClient class. 'soap_version' => SOAP_1_2 is used for SOAP 1.2.

According to the manual, SOAP Extension in PHP 5.3.1 does support SOAP 1.2. To use the SoapClient class for SOAP 1.2 Web services, the "soap_version" option is needed when loading the WSDL document as shown in this example:

   $client = new SoapClient($wsdl,array('soap_version' => SOAP_1_2));

Since my first RPC method based Web service, GetExchangeRate, has use="encoded", but no encodingStyle="uri". SOAP Extension does not like it. So I am going to test the GetStockPrice Web service.

Here is the example PHP program, GetStockPrice_SOAP12_Client.php:

<?php 
# GetStockPrice_SOAP12_Client.php
# Copyright (c) 2009 by Dr. Herong Yang, herongyang.com
# All rights reserved

#- Loading the WSDL document
   $server = "http://www.herongyang.com/Service/";
   $wsdl = $server . "GetStockPrice_WSDL_11_SOAP_12_RPC.wsdl";
   $client = new SoapClient($wsdl,
      array('trace' => TRUE, 'soap_version' => SOAP_1_2));

#- Calling the RPC method
   $result = $client->GetStockPrice('GOOG', 'NASDAQ', '2007-07-07');

#- Showing the result
   print "Stock price is: $result\n";

#- Showing the request and response
   print $client->__getLastRequest()."\n";
   print $client->__getLastResponse()."\n";
?>

Execution result of this example is presented below:

Stock price is: 552.16

<env:Envelope
   xmlns:env="http://www.w3.org/2003/05/soap-envelope"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:enc="http://www.w3.org/2003/05/soap-encoding">
   <env:Body>
      <env:GetStockPrice
         env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
         <stockPart xsi:type="xsd:string">GOOG</stockPart>
         <marketPart xsi:type="xsd:string">NASDAQ</marketPart>
         <datePart xsi:type="xsd:date">2007-07-07</datePart>
      </env:GetStockPrice>
   </env:Body>
</env:Envelope>

<soap:Envelope
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
   xmlns:ser="http://www.herongyang.com/Service/">
   <soap:Header/>
   <soap:Body>
      <ser:GetStockPriceResponse
         soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
         <pricePart xsi:type="xsd:decimal">552.16</pricePart>
      </ser:GetStockPriceResponse>
   </soap:Body>
</soap:Envelope>

Notice that SoapClient used SOAP 1.2 namespaces correctly in the SOAP request.

This confirms that SOAP Extension in PHP 5.3.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