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

PHP SOAP Extension

Part:   1  2   3  4 

(Continued from previous part...)

Note that SoapClient object can be constructed in two modes, WSDL mode and non-WSDL mode:

   __construct( "..."[, array options] ); # WSDL mode, many options
      # are provided by the WSDL document
   __construct( null, array options ); # non-WSDL mode, 'location'
      # and 'uri' are required options. 

SoapClient->__getFunctions() allows you to get a list of functions supported by the target node. This function is only valid in WSDL mode:

   array $a = $obj->__getFunctions();

SoapClient->__soapCall() allows you to make a RPC function call on the target SOAP node.

   $obj->__soapCall(string func_name[, array arguments [, ...]]);

Note that in WSDL mode, you can also make a RPC call as a local method on the SoapClient object:

   $obj->func_name(arg1, arg2, ...);

SoapClient->__getLastRequestHeaders() allows you to retrieve the HTTP request header lines of the last SOAP request executed. This function works only if the SoapClient object was created with the option of "trace=1".

   string $s = $obj->__getLastRequestHeaders();

SoapClient->__getLastRequest() allows you to retrieve SOAP request message of the last SOAP request executed. This function works only if the SoapClient object was created with the option of "trace=1".

   string $s = $obj->__getLastRequest();

SoapClient->__getLastResponseHeaders() allows you to retrieve the HTTP response header lines of the last SOAP request executed. This function works only if the SoapClient object was created with the option of "trace=1".

   string $s = $obj->__getLastRequestHeaders();

SoapClient->__getLastResponse() allows you to retrieve SOAP response message of the last SOAP request executed. This function works only if the SoapClient object was created with the option of "trace=1".

   string $s = $obj->__getLastResponse();

GetTempDump.php - Dumping Debugging Information

After learning the basic functions of the SoapClient class, I rewrote the GetTemp.php client program to get more information on how SOAP Extension works, and to show you how to debug information. The new client program is called, GetTempDump.php:

<?php # GetTempDump.php
# Copyright (c) 2005 by Dr. Herong Yang
#
   $zip = "123456";
   $client = new SoapClient
      ("http://www.xmethods.net/sd/2001/DemoTemperatureService.wsdl",
      array('trace' => 1));

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

   echo("\nDumping client object functions:\n");
   var_dump($client->__getFunctions());

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

   $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());
?>

Output of this program:

Dumping client object:
object(SoapClient)#1 (3) {
  ["trace"]=>
  int(1)
  ["_soap_version"]=>
  int(1)
  ["sdl"]=>
  resource(5) of type (Unknown)
}

Dumping client object functions:
array(1) {
  [0]=>
  string(30) "float getTemp(string $zipcode)"
}

Returning value of getTemp() call: 52

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: ""
Content-Length: 510
Cookie: JSESSIONID=uuqkGDvtzw_IPlMLsodnVX9j;

(Continued on next part...)

Part:   1  2   3  4 

Dr. Herong Yang, updated in 2006
Herong's Tutorial Notes on Web Service and SOAP - PHP SOAP Extension