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 by Dr. Herong Yang, 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

 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