PHP
  Home arrow PHP arrow Page 2 - Developing SOAP Clients using PHP
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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: starstarstarstarstar / 7
    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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT