Automatically Generating WSDL with PEAR::SOAP


PEAR::SOAP can also automatically create WSDL; however, it needs some assistance by the programmer. First, the constructor of the Web Service's class must set a __dispatch_map property that contains a list of input and output parameters. The __dispatch_map property is an array (therefore, several operations per Web Service are supported), and the name of the function is the key for the signature.

Also, you need some code that checks the URL. If ?wsdl is appended, the WSDL must be returned by the service. For this, the SOAP_DISCO_Server class is instantiated and then its method getWSDL() gets called.

A WSDL-enabled Web Service with NuSOAP (wsdl-nusoap-server.php; excerpt)
 class ServiceClass {   var $__dispatch_map = array();   function ServiceClass() {     $this->__dispatch_map['add'] = array(       'in'  => array('a' => 'int', 'b' => 'int'),       'out' => array('c' => 'int')     );   }   function __dispatch($method) {     if (isset($this->__dispatch_map[$method])) {       return $this->__dispatch_map[$method];     } else {       return null;     }   }   .. } 

The following contains the rest of the code for the server; as you would expect, calling the URL with ?wsdl at the end creates the service's WSDL description.

 <?php   error_reporting(E_ALL ^ E_NOTICE);   require_once 'SOAP/Server.php';   $soap = new SOAP_Server;   $service = new ServiceClass();   $soap->addObjectMap($service, 'urn:php-phrasebook-     soapservice');   if (isset($_SERVER['REQUEST_METHOD']) &&     $_SERVER['REQUEST_METHOD'] == 'POST') {     $soap->service($HTTP_RAW_POST_DATA);   } else {     require_once 'SOAP/Disco.php';     $disco = new SOAP_DISCO_Server($soap,        'DiscoServer');     if (isset($_SERVER['QUERY_STRING']) &&        strpos($_SERVER['QUERY_STRING'], 'wsdl') ===          0) {       header('Content-type: text/xml');       echo $disco->getWSDL();     }   }   class ServiceClass {     // ...   } ?> 




PHP Phrasebook
PHP Phrasebook
ISBN: 0672328178
EAN: 2147483647
Year: 2005
Pages: 193

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net