SOAP
[ class tree: SOAP ] [ index: SOAP ] [ all elements ]

Source for file disco_server.php

Documentation is available at disco_server.php

  1. <?php
  2. /**
  3.  * This example shows how to mark up a server object so that WSDL files may be
  4.  * dynamicaly generated by the SOAP server.  This also provides access to a
  5.  * generated DISCO document.  The fact that this example has an MP3 class is
  6.  * in no way related to DISCO. ;)
  7.  *
  8.  * DISCO: http://msdn.microsoft.com/msdnmag/issues/02/02/xml/default.aspx
  9.  *
  10.  * Urls accessing this server would look like:
  11.  * - http://localhost/disco_server.php?wsdl (generate WSDL file)
  12.  * - http://localhost/disco_server.php (GET request generates DISCO)
  13.  * - http://localhost/disco_server.php (POST for normal SOAP requests)
  14.  *
  15.  * PHP versions 4 and 5
  16.  *
  17.  * LICENSE: This source file is subject to version 2.02 of the PHP license,
  18.  * that is bundled with this package in the file LICENSE, and is available at
  19.  * through the world-wide-web at http://www.php.net/license/2_02.txt.  If you
  20.  * did not receive a copy of the PHP license and are unable to obtain it
  21.  * through the world-wide-web, please send a note to license@php.net so we can
  22.  * mail you a copy immediately.
  23.  *
  24.  * @category   Web Services
  25.  * @package    SOAP
  26.  * @author     Shane Caraveo <Shane@Caraveo.com>   Port to PEAR and more
  27.  * @author     Jan Schneider <jan@horde.org>       Maintenance
  28.  * @copyright  2003-2007 The PHP Group
  29.  * @license    http://www.php.net/license/2_02.txt  PHP License 2.02
  30.  * @link       http://pear.php.net/package/SOAP
  31.  */
  32.  
  33.  
  34. /** SOAP_Server */
  35. require_once 'SOAP/Server.php';
  36.  
  37. /**
  38.  * MP3 database class.
  39.  *
  40.  * @package SOAP
  41.  */
  42. {
  43.  
  44.     var $__dispatch_map = array();
  45.     var $__typedef = array();
  46.  
  47.     function MP3DB_Class()
  48.     {
  49.         /* The only way to describe all methods in WSDL (messages,
  50.          * PortType-operations and bindings) is to use __dispatch_map to
  51.          * describe every method (even methods using simple data types in 'in'
  52.          * and 'out' parameters...) */
  53.         $this->__dispatch_map['SayHallo'=
  54.             array('in' => array('input' => 'string'),
  55.                   'out' => array('return' => 'string'));
  56.         $this->__dispatch_map['SayThisNTimes'=
  57.             array('in' => array('SayThis'=>'string','NTimes' => 'int'),
  58.                   'out' => array('return' => '{urn:MP3DB}ArrayOfStrings'));
  59.         $this->__dispatch_map['GetMP3Tracks'=
  60.             array('in' => array('query' => 'string'),
  61.                   'out' => array('return' => '{urn:MP3DB}GetMP3TracksResult'));
  62.         $this->__dispatch_map['AddMP3Track'=
  63.             array('in' => array('MP3Track' => '{urn:MP3DB}MP3Track'),
  64.                   'out' => array('return' => '{urn:MP3DB}AddMP3TrackResult'));
  65.  
  66.         /* Use __typedef to describe userdefined Types in WSDL.  Structs and
  67.          * one-dimensional arrays are supported.
  68.          *
  69.          * Struct example:
  70.          * $this->__typedef['TypeName'] = array('VarName' => 'xsdType', ... );
  71.          * or
  72.          * $this->__typedef['TypeName'] = array('VarName' => '{namespace}SomeOtherType');
  73.          *
  74.          * Array example:
  75.          * $this->__typedef['TypeName'] = array(array('item' => 'xsdType'));
  76.          * or
  77.          * $this->__typedef['TypeName'] = array(array('item' => '{namespace}SomeOtherType'));
  78.          */
  79.  
  80.         /* Struct 'MP3Track'. */
  81.         $this->__typedef['MP3Track'=
  82.             array('Title' => 'string',
  83.                   'Artist' => 'string',
  84.                   'Album' => 'string',
  85.                   'Year' => 'int',
  86.                   'Genre' => 'int',
  87.                   'Comment' => 'string',
  88.                   'Composer' => 'string',
  89.                   'Orig_Artist' => 'string',
  90.                   'URL' => 'string',
  91.                   'Encoded_by' => 'string');
  92.  
  93.         /* MP3TracksArray - array of 'MP3Track' structs. */
  94.         $this->__typedef['MP3TracksArray'=
  95.             array(array('item' => '{urn:MP3DB}MP3Track'));
  96.  
  97.         /* Struct 'MethodDebug'. */
  98.         $this->__typedef['MethodDebug'=
  99.             array('rc' => 'boolean',
  100.                   'ErrNo' => 'int',
  101.                   'Error' => 'string');
  102.  
  103.         /* Return Struct of method GetMP3Tracks. */
  104.         $this->__typedef['GetMP3TracksResult'=
  105.             array('MethodDebug' => '{urn:MP3DB}MethodDebug',
  106.                   'MP3Tracks' => '{urn:MP3DB}MP3TracksArray');
  107.  
  108.         /* Return Struct of method AddMP3Track. */
  109.         $this->__typedef['AddMP3TrackResult'=
  110.             array('MethodDebug' => '{urn:MP3DB}MethodDebug');
  111.  
  112.         /* Array of strings. */
  113.         $this->__typedef['ArrayOfStrings'=
  114.             array(array('item'=>'string'));
  115.     }
  116.  
  117.     function SayHallo($name)
  118.     {
  119.         return 'Hello, ' $name;
  120.     }
  121.  
  122.  
  123.     function SayThisNTimes($SayThis$NTimes)
  124.     {
  125.         for ($i = 0; $i $NTimes$i++{
  126.             $return[$i$SayThis ' ' $i;
  127.         }
  128.         return new SOAP_Value('return''{urn:MP3DB}ArrayOfStrings'$return);
  129.     }
  130.  
  131.     function GetMP3Tracks($query '')
  132.     {
  133.         for ($i = 0; $i < 5; $i++{
  134.             $this->MP3Tracks[$i= new SOAP_Value(
  135.                 'item',
  136.                 '{urn:MP3DB}MP3Track',
  137.                 array('Title'       => new SOAP_Value('Title''string''some track $i'),
  138.                       'Artist'      => new SOAP_Value('Artist''string''some artist $i'),
  139.                       'Album'       => new SOAP_Value('Album''string''some album $i'),
  140.                       'Year'        => new SOAP_Value('Year''int'1999),
  141.                       'Genre'       => new SOAP_Value('Genre''int'100),
  142.                       'Comment'     => new SOAP_Value('Comment''string''blabla $i'),
  143.                       'Composer'    => new SOAP_Value('Composer''string'''),
  144.                       'Orig_Artist' => new SOAP_Value('Orig_Artist''string'''),
  145.                       'URL'         => new SOAP_Value('URL''string'''),
  146.                       'Encoded_by'  => new SOAP_Value('Encoded_by''string''')));
  147.         }
  148.  
  149.         $MethodDebug['rc']    = new SOAP_Value('rc''boolean'true);
  150.         $MethodDebug['ErrNo'= new SOAP_Value('ErrNo''int'0);
  151.         $MethodDebug['Error'= new SOAP_Value('Error''string''');
  152.  
  153.         return new SOAP_Value(
  154.             'return',
  155.             '{urn:MP3DB}GetMP3TracksResult',
  156.             array('MethodDebug' => new SOAP_Value('MethodDebug''{urn:MP3DB}MethodDebug',$MethodDebug),
  157.                   'MP3Tracks'   => new SOAP_Value('MP3Tracks''{urn:MP3DB}MP3TracksArray',$this->MP3Tracks)));
  158.     }
  159.  
  160.     function AddMP3Track($MP3Track)
  161.     {
  162.         /* Well, let's imagine here some code for adding given mp3track to db
  163.          * or whatever... */
  164.         $MethodDebug['rc']    = new SOAP_Value('rc''boolean'true);
  165.         $MethodDebug['ErrNo'= new SOAP_Value('ErrNo''int'0);
  166.         $MethodDebug['Error'= new SOAP_Value('Error''string''');
  167.  
  168.         return new SOAP_Value(
  169.             'return',
  170.             '{urn:MP3DB}AddMP3TrackResult',
  171.             array('MethodDebug' => new SOAP_Value('MethodDebug''{urn:MP3DB}MethodDebug'$MethodDebug)));
  172.     }
  173.  
  174.     function __dispatch($methodname)
  175.     {
  176.         if (isset($this->__dispatch_map[$methodname])) {
  177.             return $this->__dispatch_map[$methodname];
  178.         }
  179.         return null;
  180.     }
  181.  
  182. }
  183.  
  184. $server = new SOAP_Server();
  185. $server->_auto_translation = true;
  186. $MP3DB_Class = new MP3DB_Class();
  187. $server->addObjectMap($MP3DB_Class'urn:MP3DB');
  188.  
  189. if (isset($_SERVER['REQUEST_METHOD']&&
  190.     $_SERVER['REQUEST_METHOD'== 'POST'{
  191.     $server->service($HTTP_RAW_POST_DATA);
  192. else {
  193.     require_once 'SOAP/Disco.php';
  194.     $disco = new SOAP_DISCO_Server($server'MP3DB');
  195.     header('Content-type: text/xml');
  196.     if (isset($_SERVER['QUERY_STRING']&&
  197.         strpos($_SERVER['QUERY_STRING']'wsdl'!== false{
  198.         echo $disco->getWSDL();
  199.     else {
  200.         echo $disco->getDISCO();
  201.     }
  202. }

Documentation generated on Mon, 04 Aug 2008 20:00:18 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.