Home arrow PHP arrow Page 2 - Developing SOAP Clients using PHP

Debugging NuSOAP - PHP

SOAP (Simple Object Access Protocol) provides a flexible communication layer between applications, regardless of platform and location. As long as both the server and the client speak SOAP, they can communicate. A PHP-based web application can ask a Java database application to get some information. In this article we will try to focus on different methods of developing SOAP web service clients in PHP.

TABLE OF CONTENTS:
  1. Developing SOAP Clients using PHP
  2. Debugging NuSOAP
  3. PEAR::SOAP
  4. PHP's SOAP Extension
By: Mamun Zaman
Rating: starstarstarstarstar / 10
August 14, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

NuSOAP has some debugging features also. They are:

  1. $client->request: This is used to get the SOAP request message.
  2. $client->response: This is used to get the SOAP response message.
  3. $client->debug_str: This is used to get the debug information.
  4. $client->fault: This is used to get faults during a remote method call.

We can use all of these to check and display all errors. Here is a complete example.

<?php
require_once('nusoap.php');

$client = new soapclient('http://localhost/add.php');

$err = $client->getError();
if ($err) {
    echo '<p><b>Constructor error: ' . $err . '</b></p>';
}
else{
     $result = $client->call('add', array('a' => 5, 'b' => 7));
     if ($client->fault) {
    
     echo '<p><b>Fault: ';
    
     print_r($result);
          echo '</b></p>';
          echo '<p><b>Request: <br>';
          echo htmlspecialchars($client->request, ENT_QUOTES) . '</b></p>';
          echo '<p><b>Response: <br>';
          echo htmlspecialchars($client->response, ENT_QUOTES) . '</b></p>';
          echo '<p><b>Debug: <br>';
          echo htmlspecialchars($client->debug_str, ENT_QUOTES) . '</b></p>';
     } else {
    
     $err = $client->getError();
    
     if ($err) {
         
     echo '<p><b>Error: ' . $err . '</b></p>';
         
     echo '<p><b>Request: <br>';
         
     echo htmlspecialchars($client->request, ENT_QUOTES) . '</b></p>';
         
     echo '<p><b>Response: <br>';
               echo htmlspecialchars($client->response, ENT_QUOTES) . '</b></p>';
         
     echo '<p><b>Debug: <br>';
          
    echo htmlspecialchars($client->debug_str, ENT_QUOTES) . '</b></p>';
    
     } else {
         
     print_r($result);
    
     }
     }
}
?>

Here we are creating a soapclient object to access the add web service. If there is any error during construction, we are printing this error. If there is no error, we are calling this remote method. If this method returns any fault then we are printing the result of this function along with the request and response SOAP messages, debug string as well. If there is no fault then we are trying to get the errors that occurred during the last method call. If there are any errors then we are printing these errors along with the SOAP request, response and debug string. If there is no error then we are printing the server response. Here is a demo SOAP request message.

POST /add.php HTTP/1.0
Host: localhost
User-Agent: NuSOAP/0.6.8 (1.81)
Content-Type: text/xml; charset=ISO-8859-1
SOAPAction: ""
Content-Length: 560

<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope
  
SOAP-ENV:encodingStyle=
      "http://schemas.xmlsoap.org/soap/encoding/"
   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
   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/"
   xmlns:si="http://soapinterop.org/xsd">
  <SOAP-ENV:Body>
    
<ns1:add xmlns:ns1="http://testuri.org">
      
<a xsi:type="xsd:integer">5</a>
      
<b xsi:type="xsd:integer">7</b>
    
</ns1:add>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Here is a demo SOAP response message.

HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Wed, 25 Jul 2007 21:32:34 GMT
X-Powered-By: ASP.NET
X-Powered-By: PHP/4.3.4
Server: NuSOAP Server v0.6.8
X-SOAP-Server: NuSOAP/0.6.8 (1.81)
Content-Type: text/xml; charset=ISO-8859-1
Content-Length: 546

<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope
  
SOAP-ENV:encodingStyle=
      "http://schemas.xmlsoap.org/soap/encoding/"
   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
   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/"
   xmlns:si="http://soapinterop.org/xsd">
  
<SOAP-ENV:Body>
    
<ns1:addResponse xmlns:ns1="http://tempuri.org">
      
<return xsi:type="xsd:integer">12</return>
    
</addResponse>
  
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Using NuSOAP is very simple for developing PHP web clients as described in previous code examples. Now we will try to learn about PEAR::SOAP.



 
 
>>> More PHP Articles          >>> More By Mamun Zaman
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: