Herong's Tutorial Notes on Web Service and SOAP
Dr. Herong Yang, Version 3.00

Using SOAP Extension in non-WDSL Mode

This section describes a tutorial example on how to use PHP SOAP Extension client functions without WSDL.

I think we had enough fun with the WSDL mode. Let's try the non-WSDL mode now. Here is the third version of my getTemp SOAP client program, GetTempNonWsdl.php:

<?php # GetTempNonWsdl.php
# Copyright (c) 2005 by Dr. Herong Yang
#
   $zip = "123456";
   $client = new SoapClient(null, array(
      'location' => 
         "http://services.xmethods.net:80/soap/servlet/rpcrouter",
      'uri'      => "urn:xmethods-Temperature-Demo", 
      'trace'    => 1 ));

   echo("\nDumping client object:\n");
   var_dump($client);

   $return = $client->__soapCall("getTemp",array($zip));
   echo("\nReturning value of __soapCall() call: ".$return);

   echo("\nDumping request headers:\n" 
      .$client->__getLastRequestHeaders());

   echo("\nDumping request:\n".$client->__getLastRequest());

   echo("\nDumping response headers:\n"
      .$client->__getLastResponseHeaders());

   echo("\nDumping response:\n".$client->__getLastResponse());
?>

Here is output:

Dumping client object:
object(SoapClient)#1 (4) {
  ["uri"]=>
  string(29) "urn:xmethods-Temperature-Demo"
  ["location"]=>
  string(54) "http://services.xmethods.net:80/soap/servlet/rpcrouter"
  ["trace"]=>
  int(1)
  ["_soap_version"]=>
  int(1)
}

Returning value of __soapCall() call: 52

Dumping request headers:
POST /soap/servlet/rpcrouter HTTP/1.1
Host: services.xmethods.net
Connection: Keep-Alive
User-Agent: PHP SOAP 0.1
Content-Type: text/xml; charset=utf-8
SOAPAction: "urn:xmethods-Temperature-Demo#getTemp"
Content-Length: 508

Dumping request:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:ns1="urn:xmethods-Temperature-Demo" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
 SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
 <SOAP-ENV:Body><ns1:getTemp>
  <param0 xsi:type="xsd:string">123456</param0>
 </ns1:getTemp></SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Dumping response headers:
HTTP/1.1 200 OK
Date: Wed, 05 Oct 2005 02:02:46 GMT
Server: Enhydra-MultiServer/3.1.1b1
Status: 200
Content-Type: text/xml; charset=utf-8
Servlet-Engine: Enhydra Application Server/3.1.1b1 (JSP 1.1;
   Servlet 2.2; Java 1.4.2_03; Linux 2.4.7-10smp i386;
   java.vendor=Sun Microsystems Inc.)
Content-Length: 470
Set-Cookie: JSESSIONID=RTiE9NZhFiqCdnPB36zgsXMi;Path=/soap
X-Cache: MISS from www.xmethods.net
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive

Dumping response:
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:getTempResponse
 xmlns:ns1="urn:xmethods-Temperature-Demo"
 SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<return xsi:type="xsd:float">52.0</return>
</ns1:getTempResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Output shows that:

  • My GetTempNonWsdl.php works the same as the WSDL mode version.
  • If you compare this output with the WSDL output, SOAP Extension generates the request headers with one difference: SOAPAction is not blank any more. It has the value of "urn:xmethods-Temperature-Demo#getTemp".
  • SOAP Extension also generates the request message differently in non-WSDL mode. The input parameter is provided with an element named as "param0". In the WSDL version, that element is named as "zipcode".

Sections in This Chapter

What Is PHP SOAP Extension?

GetTemp.php - First Example with SOAP

PHP SOAP Extension Functions for Client Programs

GetTempDump.php - Dumping Debugging Information

Whis Is WSDL (Web Services Definition Language)?

Using SOAP Extension in non-WDSL Mode

Dr. Herong Yang, updated in 2007
Using SOAP Extension in non-WDSL Mode