example_server.php
6.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Shane Caraveo <Shane@Caraveo.com> |
// +----------------------------------------------------------------------+
//
// $Id$
//
// first, include the SOAP/Server class
require_once 'SOAP/Value.php';
require_once 'SOAP/Fault.php';
// SOAPStruct is defined in the following file
require_once 'example_types.php';
// create a class for your soap functions
class SOAP_Example_Server {
/**
* The dispactch map does not need to be used, but aids
* the server class in knowing what parameters are used
* with the functions. This is the ONLY way to have
* multiple OUT parameters. If you use a dispatch map, you
* MUST add ALL functions you wish to allow be called. If
* you do not use a dispatch map, then any public function
* can be called from soap (in php4, we consider this to be
* any function in the class unless it starts with underscore,
* php5 support is not complete yet in this regard).
* if you do not define in/out parameters, the function can be
* called with parameters, but no validation on parameters will
* occure.
*/
var $__dispatch_map = array();
function SOAP_Example_Server() {
/**
* when generating wsdl for a server, you have to define
* any special complex types that you use (ie classes).
* using a namespace id before the type will create an
* xml schema with the targetNamespace for the type
* multiple types with the same namespace will appear
* in the same schema section. types with different
* namespaces will be in seperate schema sections.
* the following SOAPStruct typedef cooresponds to the
* SOAPStruct class above.
*/
$this->__typedef['{http://soapinterop.org/xsd}SOAPStruct'] =
array(
'varString' => 'string',
'varInt' => 'int',
'varFloat' => 'float'
);
// an aliased function with multiple out parameters
$this->__dispatch_map['echoStructAsSimpleTypes'] =
array('in' => array('inputStruct' => '{http://soapinterop.org/xsd}SOAPStruct'),
'out' => array('outputString' => 'string', 'outputInteger' => 'int', 'outputFloat' => 'float'),
'alias' => 'myEchoStructAsSimpleTypes'
);
$this->__dispatch_map['echoStringSimple'] =
array('in' => array('inputStringSimple' => 'string'),
'out' => array('outputStringSimple' => 'string'),
);
$this->__dispatch_map['echoString'] =
array('in' => array('inputString' => 'string'),
'out' => array('outputString' => 'string'),
);
$this->__dispatch_map['divide'] =
array('in' => array('dividend' => 'int', 'divisor' => 'int'),
'out' => array('outputFloat' => 'float'),
);
$this->__dispatch_map['echoStruct'] =
array('in' => array('inputStruct' => '{http://soapinterop.org/xsd}SOAPStruct'),
'out' => array('outputStruct' => '{http://soapinterop.org/xsd}SOAPStruct'),
);
$this->__dispatch_map['echoMimeAttachment'] = array();
}
/* this private function is called on by SOAP_Server to determine any
special dispatch information that might be necessary. This, for example,
can be used to set up a dispatch map for functions that return multiple
OUT parameters */
function __dispatch($methodname) {
if (isset($this->__dispatch_map[$methodname]))
return $this->__dispatch_map[$methodname];
return NULL;
}
// a simple echoString function
function echoStringSimple($inputString)
{
return $inputString;
}
// an explicit echostring function
function echoString($inputString)
{
return new SOAP_Value('outputString','string',$inputString);
}
function divide($dividend, $divisor)
{
// the soap server would normally catch errors like this
// and return a fault, but this is how you do it yourself.
if ($divisor == 0)
return new SOAP_Fault('You cannot divide by zero', 'Client');
else
return $dividend / $divisor;
}
function echoStruct($inputStruct)
{
return $inputStruct->__to_soap('outputStruct');
#return new SOAP_Value('outputStruct','{http://soapinterop.org/xsd}SOAPStruct',$inputStruct);
}
/**
* echoStructAsSimpleTypes
* takes a SOAPStruct as input, and returns each of its elements
* as OUT parameters
*
* this function is also aliased so you have to call it with
* echoStructAsSimpleTypes
*
* SOAPStruct is defined as:
*
* struct SOAPStruct:
* string varString
* integer varInt
* float varFloat
*
*/
function myEchoStructAsSimpleTypes($struct)
{
# convert a SOAPStruct to an array
return array(
new SOAP_Value('outputString','string',$struct->varString),
new SOAP_Value('outputInteger','int',$struct->varInt),
new SOAP_Value('outputFloat','float',$struct->varFloat)
);
}
function echoMimeAttachment($stuff)
{
return new SOAP_Attachment('return','application/octet-stream',NULL,$stuff);
}
}
?>