Zend
  Home arrow Zend arrow Page 5 - PHP SOAP Extension
Dev Shed Forums 
Administration  
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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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? 
ZEND

PHP SOAP Extension
By: Zend
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 18
    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:
      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

    PCmover - $15 Off with Coupon Code CJPH7Q

    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-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway