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

Documentation generated on Mon, 11 Mar 2019 14:54:40 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.