Zend
  Home arrow Zend arrow Page 5 - PHP SOAP Extension
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? 
Google.com  
ZEND

PHP SOAP Extension
By: Zend
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 20
    2004-03-17


    Table of Contents:
  • PHP SOAP Extension
  • A First SOAP Client
  • Using WSDL
  • A First SOAP Server
  • Creating the Server
  • Example 6
  • Example 8 (client5.php)
  • Other Implementations of SOAP for PHP

  • 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


    PHP SOAP Extension - Creating the Server
    ( Page 5 of 8 )


    Now it’s time to create our server.
    First, we’ll implement the getQuote() function, which will be accessed as a service function by incoming request messages from the web. Next, we’ll create a SoapServer object and connect it with the service function using SoapServer::addFunction() method. As you will see, the SoapServer() constructor has only one parameter: the path of the WSDL document that describes the service.

    Example 4 (server1. php)


    <?php
    $quotes 
    = array(
      
    "ibm" => 98.42
    );  
    function 
    getQuote($symbol) {
      
    global $quotes;
      
    return $quotes[$symbol];
    }
    ini_set("soap.wsdl_cache_enabled""0"); // disabling WSDL cache
    $server = new SoapServer("stockquote1.wsdl");
    $server->addFunction("getQuote");
    $server->handle();




    The SoapServer can work without a WSDL document in much the same way that the SoapClient can, but there are no obvious benefits to be had from setting it up in this way. Were you to do so, you should ensure that the return values are special objects of the SoapParam and SoapVar classes (as in the first example).

    Here is a client for accessing our own SOAP server. Nothing has changed from the previous example except the WSDL location. It assumes that “stockquote1.wsdl” is in the same directory as our SOAP server.

    Example 5 (client3.php)


    <?php
      $client 
    = new SoapClient("stockquote1.wsdl");
      
    print($client->getQuote("ibm"));? >


    What are the problem areas with our server and client?

    To start with, they don’t handle errors. What happens when the server doesn’t recognize the requested symbol?  The SOAP protocol specifies a special format of messages for reporting errors – SoapFault. To generate such messages the server should throw an exception using the SoapFault object. The first parameter to the SoapFault() constructor is a fault code string, and the second is a fault description string. The client should be written in such a way as to catch SoapFault exceptions.

    Secondly, it would be better to encapsulate Web Service functionality in a PHP class. In this case we wouldn’t need to use global variables and add each SOAP method to the server individually; we could add an entire class, and all its methods would be accessible through SOAP.



     
     
    >>> More Zend Articles          >>> More By Zend
     

       

    ZEND ARTICLES

    - Taking the Zend Certified PHP Engineer Exam:...
    - Quick Introduction to PHP 5
    - PHP SOAP Extension
    - Improving Performance
    - PDFs with PHP part 2
    - PDFs with PHP part 1
    - PHP at Lycos
    - Build Database Interfaces





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek