Hello_There_Dump.php - Debugging SOAP Messages

This section provides a tutorial example on how to use SOAP client functions to make Web service call on the target SOAP node and print detailed debug information.

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

<?php
#  Hello_There_Dump.php
#- Copyright 2009-2015 (c) HerongYang.com. All Rights Reserved.
#
   $client = new SoapClient
      ("http://herongyang.com/Service/Hello_WSDL_11_SOAP.wsdl",
      array('trace' => 1));

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

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

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

   $return = $client->__soapCall("Hello",array());
   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());
?>

If you run this sample script, you will get:

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

Dumping client object functions:
array(1) {
  [0]=>
  string(36) "string Hello(string $helloInputPart)"
}

Returning value of Hello() call:
      Hello from server - herongyang.com.

Returning value of __soapCall() call:
      Hello from server - herongyang.com.

Dumping request headers:
POST /Service/Hello_SOAP_11.php HTTP/1.1
Host: www.herongyang.com
Connection: Keep-Alive
User-Agent: PHP-SOAP/7.3.0
Content-Type: text/xml; charset=utf-8
SOAPAction: "https://www.herongyang.com/Service/Hello"
Content-Length: 235


Dumping request:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:ns1="https://www.herongyang.com/Service/">
 <SOAP-ENV:Body>
  <ns1:HelloRequest/>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Dumping response headers:
HTTP/1.1 200 OK
Server: Apache
X-Powered-By: PHP/7.2.14
Keep-Alive: timeout=2, max=199
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/xml

Dumping response:
<soapenv:Envelope
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:hy="https://www.herongyang.com/Service/">
  <soapenv:Header/>
  <soapenv:Body>
    <hy:HelloResponse>
      Hello from server - herongyang.com.
    </hy:HelloResponse>
  </soapenv:Body>
</soapenv:Envelope>

The output is very useful. It confirms that:

Table of Contents

 About This Book

 Introduction and Installation of PHP

 Managing PHP Engine and Modules on macOS

 Managing PHP Engine and Modules on CentOS

 cURL Module - Client for URL

 DOM Module - Parsing HTML Documents

 GD Module - Manipulating Images and Pictures

 MySQLi Module - Accessing MySQL Server

 OpenSSL Module - Cryptography and SSL/TLS Toolkit

 PCRE Module - Perl Compatible Regular Expressions

SOAP Module - Creating and Calling Web Services

 SOAP Module and PHP Implementations of SOAP

 Turning on the Default SOAP Module

 Hello_There.php - First Example of SOAP

 SoapClient - SOAP Client Class and Functions

Hello_There_Dump.php - Debugging SOAP Messages

 What Is WSDL

 Using SOAP Extension in non-WSDL Mode

 SOAP Module - Server Functions and Examples

 Zip Module - Managing ZIP Archive Files

 References

 Full Version in PDF/EPUB