XSD_ANYXML Encoding - Building SOAP Body Element

This section provides a tutorial example to show different behaviors of SoapClient on XML document based Web services.

One important thing I learned from the previous tutorial is that XSD_ANYXML can be used to provide an input parameter as a raw XML string. This feature can be used to call XML document based Web services.

Let's look at my simplest XML document based Web service, Hello, again. The WSDL document is located at http://www.herongyang.com/Service/ Hello_WSDL_11_SOAP.wsdl. Here is the WSDL part that defines the request XML document:

  <wsdl:types>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      targetNamespace="http://www.herongyang.com/Service/">
      <xsd:element name="HelloRequest" type="xsd:string"/>
      ...
    </xsd:schema>
  </wsdl:types>

  <wsdl:message name="helloInputMessage">
    <wsdl:part name="helloInputPart" element="hy:HelloRequest"/>
  </wsdl:message>
  ...

The expected request should look at this:

<soapenv:Envelope
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:ser="http://www.herongyang.com/Service/">
  <soapenv:Header/>
  <soapenv:Body>
    <ser:HelloRequest>Hello from client.</ser:HelloRequest>
  </soapenv:Body>
</soapenv:Envelope>

I wrote the following program, SoapClient_XSD_ANYXML.php, to test how SoapClient behaves on the Hello service:

<?php 
# SoapClient_XSD_ANYXML.php
# Copyright (c) 2009 HerongYang.com, All Rights Reserved.
#
#- Loading the WSDL document
   $server = "http://www.herongyang.com/Service/";
   $wsdl = $server . "Hello_WSDL_11_SOAP.wsdl";
   $client = new SoapClient($wsdl,
      array('trace' => TRUE));

#- Test 1: Calling with a string directly
   $input = "Hello as a string";
   $result = $client->Hello($input);
   print $client->__getLastRequest()."\n";

#- Test 2: Calling with a SoapParam object
   $input = new SoapParam("Hello as a SoapParam object", "SoapParam");
   $result = $client->Hello($input);
   print $client->__getLastRequest()."\n";

#- Test 3: Calling with a XSD_ANYXML SoapVar object
   $input = new SoapVar(
     "<SoapVar>Hello as an XSD_ANYXML SoapVar object</SoapVar>", 
     XSD_ANYXML);
   $result = $client->Hello($input);
   print $client->__getLastRequest()."\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>
    <ns1:HelloRequest>Hello as a string</ns1:HelloRequest>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

<SOAP-ENV:Envelope
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:ns1="http://www.herongyang.com/Service/">
  <SOAP-ENV:Body>
    <ns1:HelloRequest>Hello as a SoapParam object</ns1:HelloRequest>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

<SOAP-ENV:Envelope
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:ns1="http://www.herongyang.com/Service/">
  <SOAP-ENV:Body>
    <SoapVar>Hello as an XSD_ANYXML SoapVar object</SoapVar>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

This result is very interesting:

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

 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

 WSDL Related Terminologies

 Outdated Tutorials

 References

 Full Version in PDF/EPUB