| 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 | // | [email protected] so we can mail you a copy immediately. |
|
|---|
| 15 | // +----------------------------------------------------------------------+
|
|---|
| 16 | // | Author: Dmitri Vinogradov <[email protected]> |
|
|---|
| 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 | error_reporting(E_ALL);
|
|---|
| 38 | require_once 'SOAP/Server.php';
|
|---|
| 39 |
|
|---|
| 40 | class MP3DB_Class {
|
|---|
| 41 | var $__dispatch_map = array();
|
|---|
| 42 | var $__typedef = array();
|
|---|
| 43 |
|
|---|
| 44 | function MP3DB_Class () {
|
|---|
| 45 | /**
|
|---|
| 46 | * the only way to describe all methods in WSDL (messages,
|
|---|
| 47 | * PortType-operations and bindings) is to use __dispatch_map
|
|---|
| 48 | * to describe every method (even methods using simple data
|
|---|
| 49 | * types in 'in' and 'out' parameters...)
|
|---|
| 50 | */
|
|---|
| 51 |
|
|---|
| 52 | $this->__dispatch_map['SayHallo'] =
|
|---|
| 53 | array(
|
|---|
| 54 | 'in' => array('input' => 'string'),
|
|---|
| 55 | 'out' => array('return' => 'string')
|
|---|
| 56 | );
|
|---|
| 57 |
|
|---|
| 58 | $this->__dispatch_map['SayThisNTimes'] =
|
|---|
| 59 | array(
|
|---|
| 60 | 'in' => array('SayThis'=>'string','NTimes' => 'int'),
|
|---|
| 61 | 'out' => array('return' => '{urn:MP3DB}ArrayOfStrings')
|
|---|
| 62 | );
|
|---|
| 63 |
|
|---|
| 64 | $this->__dispatch_map['GetMP3Tracks'] =
|
|---|
| 65 | array(
|
|---|
| 66 | 'in' => array('query' => 'string'),
|
|---|
| 67 | 'out' => array('return' => '{urn:MP3DB}GetMP3TracksResult')
|
|---|
| 68 | );
|
|---|
| 69 |
|
|---|
| 70 | $this->__dispatch_map['AddMP3Track'] =
|
|---|
| 71 | array(
|
|---|
| 72 | 'in' => array('MP3Track' => '{urn:MP3DB}MP3Track'),
|
|---|
| 73 | 'out' => array('return' => '{urn:MP3DB}AddMP3TrackResult')
|
|---|
| 74 | );
|
|---|
| 75 |
|
|---|
| 76 | /**
|
|---|
| 77 | * I use __typedef to describe userdefined Types in WSDL.
|
|---|
| 78 | * Structs and one-dimensional arrays are supported:
|
|---|
| 79 | * Struct example: $this->__typedef['TypeName'] = array('VarName' => 'xsdType', ... );
|
|---|
| 80 | * or $this->__typedef['TypeName'] = array('VarName' => '{namespace}SomeOtherType');
|
|---|
| 81 | * Array example: $this->__typedef['TypeName'] = array(array('item' => 'xsdType'));
|
|---|
| 82 | * or $this->__typedef['TypeName'] = array(array('item' => '{namespace}SomeOtherType'));
|
|---|
| 83 | */
|
|---|
| 84 |
|
|---|
| 85 | /**
|
|---|
| 86 | * Struct 'MP3Track'
|
|---|
| 87 | */
|
|---|
| 88 | $this->__typedef['MP3Track'] =
|
|---|
| 89 | array(
|
|---|
| 90 | 'Title' => 'string',
|
|---|
| 91 | 'Artist' => 'string',
|
|---|
| 92 | 'Album' => 'string',
|
|---|
| 93 | 'Year' => 'int',
|
|---|
| 94 | 'Genre' => 'int',
|
|---|
| 95 | 'Comment' => 'string',
|
|---|
| 96 | 'Composer' => 'string',
|
|---|
| 97 | 'Orig_Artist' => 'string',
|
|---|
| 98 | 'URL' => 'string',
|
|---|
| 99 | 'Encoded_by' => 'string'
|
|---|
| 100 | );
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 | /**
|
|---|
| 105 | * MP3TracksArray - array of 'MP3Track' structs
|
|---|
| 106 | */
|
|---|
| 107 | $this->__typedef['MP3TracksArray'] =
|
|---|
| 108 | array(
|
|---|
| 109 | array(
|
|---|
| 110 | 'item' => '{urn:MP3DB}MP3Track'
|
|---|
| 111 | )
|
|---|
| 112 | );
|
|---|
| 113 |
|
|---|
| 114 | /**
|
|---|
| 115 | * Struct 'MethodDebug'
|
|---|
| 116 | */
|
|---|
| 117 | $this->__typedef['MethodDebug'] =
|
|---|
| 118 | array(
|
|---|
| 119 | 'rc' => 'boolean',
|
|---|
| 120 | 'ErrNo' => 'int',
|
|---|
| 121 | 'Error' => 'string'
|
|---|
| 122 | );
|
|---|
| 123 |
|
|---|
| 124 | /**
|
|---|
| 125 | * return Struct of method GetMP3Tracks
|
|---|
| 126 | */
|
|---|
| 127 | $this->__typedef['GetMP3TracksResult'] =
|
|---|
| 128 | array(
|
|---|
| 129 | 'MethodDebug' => '{urn:MP3DB}MethodDebug',
|
|---|
| 130 | 'MP3Tracks' => '{urn:MP3DB}MP3TracksArray'
|
|---|
| 131 | );
|
|---|
| 132 |
|
|---|
| 133 | /**
|
|---|
| 134 | * return Struct of method AddMP3Track
|
|---|
| 135 | */
|
|---|
| 136 | $this->__typedef['AddMP3TrackResult'] =
|
|---|
| 137 | array(
|
|---|
| 138 | 'MethodDebug' => '{urn:MP3DB}MethodDebug'
|
|---|
| 139 | );
|
|---|
| 140 |
|
|---|
| 141 | /**
|
|---|
| 142 | * Array of strings
|
|---|
| 143 | */
|
|---|
| 144 | $this->__typedef['ArrayOfStrings'] =
|
|---|
| 145 | array(
|
|---|
| 146 | array('item'=>'string')
|
|---|
| 147 | );
|
|---|
| 148 |
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 | function SayHallo($name) {
|
|---|
| 153 | return "Hallo, " . $name;
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 | function SayThisNTimes($SayThis,$NTimes) {
|
|---|
| 158 | for ($i = 0; $i < $NTimes; $i++) {
|
|---|
| 159 | $return[$i] = $SayThis . " $i";
|
|---|
| 160 | }
|
|---|
| 161 | return new SOAP_Value('return','{urn:MP3DB}ArrayOfStrings',$return);
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 | function GetMP3Tracks($query = "") {
|
|---|
| 166 | for($i = 0; $i < 5; $i++) {
|
|---|
| 167 | $this->MP3Tracks[$i] = new SOAP_Value(
|
|---|
| 168 | 'item',
|
|---|
| 169 | '{urn:MP3DB}MP3Track',
|
|---|
| 170 | array(
|
|---|
| 171 | "Title" => new SOAP_Value("Title","string","some track $i"),
|
|---|
| 172 | "Artist" => new SOAP_Value("Artist","string","some artist $i"),
|
|---|
| 173 | "Album" => new SOAP_Value("Album","string","some album $i"),
|
|---|
| 174 | "Year" => new SOAP_Value("Year","int",(integer)1999),
|
|---|
| 175 | "Genre" => new SOAP_Value("Genre","int",(integer)100),
|
|---|
| 176 | "Comment" => new SOAP_Value("Comment","string","blabla $i"),
|
|---|
| 177 | "Composer" => new SOAP_Value("Composer","string",""),
|
|---|
| 178 | "Orig_Artist" => new SOAP_Value("Orig_Artist","string",""),
|
|---|
| 179 | "URL" => new SOAP_Value("URL","string",""),
|
|---|
| 180 | "Encoded_by" => new SOAP_Value("Encoded_by","string","")
|
|---|
| 181 | )
|
|---|
| 182 | );
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | $MethodDebug["rc"] = new SOAP_Value("rc","boolean",true);
|
|---|
| 186 | $MethodDebug["ErrNo"] = new SOAP_Value("ErrNo","int",(integer)0);
|
|---|
| 187 | $MethodDebug["Error"] = new SOAP_Value("Error","string","");
|
|---|
| 188 |
|
|---|
| 189 | return new SOAP_Value('return','{urn:MP3DB}GetMP3TracksResult',array(
|
|---|
| 190 | "MethodDebug" => new SOAP_Value('MethodDebug','{urn:MP3DB}MethodDebug',$MethodDebug),
|
|---|
| 191 | "MP3Tracks" => new SOAP_Value('MP3Tracks','{urn:MP3DB}MP3TracksArray',$this->MP3Tracks)
|
|---|
| 192 | )
|
|---|
| 193 | );
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 | function AddMP3Track($MP3Track) {
|
|---|
| 198 | # well, lets imagine here some code for adding given mp3track to db or whatever...
|
|---|
| 199 | $MethodDebug["rc"] = new SOAP_Value("rc","boolean",true);
|
|---|
| 200 | $MethodDebug["ErrNo"] = new SOAP_Value("ErrNo","int",(integer)0);
|
|---|
| 201 | $MethodDebug["Error"] = new SOAP_Value("Error","string","");
|
|---|
| 202 |
|
|---|
| 203 | return new SOAP_Value('return','{urn:MP3DB}AddMP3TrackResult',array(
|
|---|
| 204 | "MethodDebug" => new SOAP_Value('MethodDebug','{urn:MP3DB}MethodDebug',$MethodDebug)
|
|---|
| 205 | )
|
|---|
| 206 | );
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 | function __dispatch($methodname) {
|
|---|
| 211 | if (isset($this->__dispatch_map[$methodname]))
|
|---|
| 212 | return $this->__dispatch_map[$methodname];
|
|---|
| 213 | return NULL;
|
|---|
| 214 | }
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | $server = new SOAP_Server;
|
|---|
| 218 | $server->_auto_translation = true;
|
|---|
| 219 | $MP3DB_Class = new MP3DB_Class();
|
|---|
| 220 | $server->addObjectMap($MP3DB_Class,'urn:MP3DB');
|
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 | if (isset($_SERVER['REQUEST_METHOD']) &&
|
|---|
| 224 | $_SERVER['REQUEST_METHOD']=='POST') {
|
|---|
| 225 | $server->service($HTTP_RAW_POST_DATA);
|
|---|
| 226 | } else {
|
|---|
| 227 | require_once 'SOAP/Disco.php';
|
|---|
| 228 | $disco = new SOAP_DISCO_Server($server,"MP3DB");
|
|---|
| 229 | header("Content-type: text/xml");
|
|---|
| 230 | if (isset($_SERVER['QUERY_STRING']) &&
|
|---|
| 231 | strcasecmp($_SERVER['QUERY_STRING'],'wsdl')==0) {
|
|---|
| 232 | echo $disco->getWSDL();
|
|---|
| 233 | } else {
|
|---|
| 234 | echo $disco->getDISCO();
|
|---|
| 235 | }
|
|---|
| 236 | exit;
|
|---|
| 237 | }
|
|---|
| 238 | ?>
|
|---|