PHP
  Home arrow PHP arrow Page 2 - Developing SOAP Clients using PHP
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Developing SOAP Clients using PHP
By: Mamun Zaman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2007-08-14

    Table of Contents:
  • Developing SOAP Clients using PHP
  • Debugging NuSOAP
  • PEAR::SOAP
  • PHP's SOAP Extension

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Developing SOAP Clients using PHP - Debugging NuSOAP


    (Page 2 of 4 )

    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


       · Something not pointed out in this article, is that PHP5's SOAP extension is written...
     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT