PHP SOAP Extension - XML Document Based Web Services

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

To test XML document based Web services, I used my Reservation service. Here is my example PHP program, Reservation_SOAP12_Client.php:

<?php 
# Reservation_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 . "Reservation_WSDL_11_SOAP_12_Document.wsdl";
   $client = new SoapClient($wsdl,
      array('trace' => TRUE, 'soap_version' => SOAP_1_2));

#- Creating the XML document
   $xml = <<<EOT
<hy:Reservation xmlns:hy="http://www.herongyang.com/Service/">
  <Member>Herong Yang</Member>
  <ItemList>
    <Item>Java Web Services</Item>
    <Item>SOAP Programming</Item>
  </ItemList>
</hy:Reservation>
EOT;
   $body = new SoapVar($xml,XSD_ANYXML);

#- Calling the service method
   $result = $client->Reservation($body);

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

Here is the result of this tutorial program:

<env:Envelope
  xmlns:env="http://www.w3.org/2003/05/soap-envelope"
  xmlns:ns1="http://www.herongyang.com/Service/">
  <env:Body>
<hy:Reservation xmlns:hy="http://www.herongyang.com/Service/">
  <Member>Herong Yang</Member>
  <ItemList>
    <Item>Java Web Services</Item>
    <Item>SOAP Programming</Item>
  </ItemList>
</hy:Reservation>
  </env:Body>
</env:Envelope>

<soapenv:Envelope
  xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:hy="http://www.herongyang.com/Service/">
  <soapenv:Header/>
  <soapenv:Body>
    <hy:ReservationResponse>
      <Number>20080808</Number>
      <Status>Wait</Status>
    </hy:ReservationResponse>
  </soapenv:Body>
</soapenv:Envelope>

This proves that SOAP Extension in PHP 5.3.1 does support XML document 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