Dumping SOAP Request and Response

This section provides a tutorial example of how to dump the actual SOAP request and response message after calling a WSDL operation in RPC style.

When you call a WSDL operation in the RPC style as presented in the last two tutorials, the PHP SOAP extension is actually converting the RPC function calls into a SOAP request. After receiving the SOAP response, it will convert the response body back to a result object.

In the example below, I turned on "trace" option, and called __getLastRequestHeaders(), __getLastRequest(), __getLastResponseHeaders(), and __getLastResponse() to retrieve the actual SOAP request and response messages.

<?php 
# NumberConversionDump.php
# Copyright (c) 2007 HerongYang.com. All Rights Reserved.
#
   $client = new SoapClient
("https://www.dataaccess.com/webservicesserver/numberconversion.wso?WSDL", 
      array('trace' => 1));

   $operation = "NumberToWords";
   $inputs = array('ubiNum'=>202);
   $args = array($inputs);
   $result = $client->__soapCall($operation, $args);

   echo("Operation: $operation\n");
   echo("Arguments:\n");
   var_dump($args);
   echo("Result:\n");
   var_dump($result);

   echo("\nRequest headers:\n".$client->__getLastRequestHeaders());
   echo("\nRequest:\n".$client->__getLastRequest());
   echo("\nResponse headers:\n".$client->__getLastResponseHeaders());
   echo("\nResponse:\n".$client->__getLastResponse());
?>

When running it, I am getting:

herong> php NumberConversionDump.php

Operation: NumberToWords
Arguments:
array(1) {
  [0]=>
  array(1) {
 ["ubiNum"]=>
 int(202)
  }
}
Result:
object(stdClass)#2 (1) {
  ["NumberToWordsResult"]=>
  string(20) "two hundred and two "
}

Request headers:
POST /webservicesserver/numberconversion.wso HTTP/1.1
Host: www.dataaccess.com
Connection: Keep-Alive
User-Agent: PHP-SOAP/7.0.2
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
Content-Length: 293


Request:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:ns1="http://www.dataaccess.com/webservicesserver/">
 <SOAP-ENV:Body>
  <ns1:NumberToWords>
   <ns1:ubiNum>202</ns1:ubiNum>
  </ns1:NumberToWords>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Response headers:
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Length: 352
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/8.0
Web-Service: DataFlex 18.1
Strict-Transport-Security: max-age=31536000

Response:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
 <soap:Body>
  <m:NumberToWordsResponse
   xmlns:m="http://www.dataaccess.com/webservicesserver/">
   <m:NumberToWordsResult>two hundred and two </m:NumberToWordsResult>
  </m:NumberToWordsResponse>
 </soap:Body>
</soap:Envelope>

With the SOAP request and response messages printed out, we can figure out the following rules used by SoapClient the RPC calls:

What happens if the SOAP request or response message has a multi-level element structure? The RPC style of calling the WSDL operation may not work.

Table of Contents

 About This Book

 Introduction to Web Service

 Introduction to SOAP (Simple Object Access Protocol)

 SOAP Message Structure

 SOAP Message Transmission and Processing

 SOAP Data Model

 SOAP Encoding

 SOAP RPC Presentation

 SOAP Properties Model

 SOAP MEP (Message Exchange Patterns)

 SOAP HTTP Binding

 SOAP PHP Implementations

PHP SOAP Extension Client Programs

 PHP SOAP Extension Functions for Client Programs

 Calling WSDL Operation Directly

 Call WSDL Operation with SoapClient::__soapCall()

Dumping SOAP Request and Response

 Call WSDL Operation with SoapClient::__doRequest()

 PHP SOAP Extension Server Programs

 PHP SOAP Web Service Example - getTemp

 SOAP Perl Implementations

 Perl SOAP::Lite - SOAP Server-Client Communication Module

 Perl Socket Test Program for HTTP and SOAP

 Perl SOAP::Lite for NumberToWords SOAP 1.1 Web Service

 Perl SOAP::Lite for SOAP 1.2 Web Services

 Perl SOAP::Lite for WSDL

 Python SOAP Client: Zeep

 SOAP Java Implementations

 Java Socket and HttpURLConnection for SOAP

 SAAJ - SOAP with Attachments API for Java

 SoapUI - SOAP Web Service Testing Tool

 WS-Security - SOAP Message Security Extension

 WS-Security X.509 Certificate Token

 Perl SOAP::Lite for GetSpeech SOAP 1.1 Web Service

 Perl SOAP::Lite 0.710 for SOAP 1.2 Web Services

 Perl SOAP::Lite 0.710 for WSDL

 Web Services and SOAP Terminology

 Archived Tutorials

 References

 Full Version in PDF/EPUB