WSDL Tutorials - Herong's Tutorial Examples - v2.22, by Herong Yang
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: https://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="https://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) 2007 HerongYang.com. All Rights Reserved. # #- Loading the WSDL document $server = "https://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="https://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="https://www.herongyang.com/Service/"> <SOAP-ENV:Body> <hy:Reservation xmlns:hy="https://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="https://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.
Table of Contents
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
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
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