Calling an XML Document Based Web Service

This section provides a tutorial example on how to write a PHP program to call an XML document based Web service using the SoapClient class with the help of SoapVar($xml,XSD_ANYXML) constructor.

Now let's try to use XSD_ANYXML SoapVar objects to build more complex XML document based Web services. One example is my Reservation service, which is located at: http://www.herongyang.com/Service/ Reservation_WSDL_11_SOAP_11_Document.wsdl. The XML document in the request should look like this:

<soapenv:Envelope
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:ser="http://www.herongyang.com/Service/">
  <soapenv:Header/>
  <soapenv:Body>
    <ser:Reservation>
      <Member>Herong Yang</hy:Member>
      <ItemList>
        <Item>Java Web Services</Item>
        <Item>SOAP Programming</Item>
      </ItemList>
    </ser:Reservation>
  </soapenv:Body>
</soapenv:Envelope>

Here is my example PHP program, Reservation_Client.php:

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

#- 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 response
   print $client->__getLastRequest()."\n";
   print $client->__getLastResponse()."\n";
?>

Here is the result of this tutorial program:

<SOAP-ENV:Envelope
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:ns1="http://www.herongyang.com/Service/">
  <SOAP-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>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

<soapenv:Envelope
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  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 SoapClient can call any XML document based Web services with the help of SoapVar($xml,XSD_ANYXML) constructor.

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

 What Is PHP SOAP Extension?

 Downloading and Installing PHP 5.3.1

 Configuring and Testing SOAP Extension

 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

 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