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.

# NumberConversionDump.php
# Copyright (c) 2007 HerongYang.com. All Rights Reserved.
   $client = new SoapClient
      array('trace' => 1));

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

   echo("Operation: $operation\n");

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

When running it, I am getting:

herong> php NumberConversionDump.php

Operation: NumberToWords
array(1) {
  array(1) {
object(stdClass)#2 (1) {
  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

<?xml version="1.0" encoding="UTF-8"?>

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

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

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


 Full Version in PDF/EPUB