1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.soap.server">
4 <title>Zend_Soap_Server</title>
7 <classname>Zend_Soap_Server</classname> class is intended to simplify Web Services server
8 part development for <acronym>PHP</acronym> programmers.
12 It may be used in WSDL or non-WSDL mode, and using classes or functions to define Web
13 Service <acronym>API</acronym>.
17 When <classname>Zend_Soap_Server</classname> component works in the WSDL mode, it uses
18 already prepared WSDL document to define server object behavior and transport layer options.
22 WSDL document may be auto-generated with functionality provided by <link
23 linkend="zend.soap.autodiscovery.introduction">Zend_Soap_AutoDiscovery component</link>
24 or should be constructed manually using <link
25 linkend="zend.soap.wsdl"><classname>Zend_Soap_Wsdl</classname> class</link> or any other
26 <acronym>XML</acronym> generating tool.
30 If the non-WSDL mode is used, then all protocol options have to be set using options
34 <sect2 id="zend.soap.server.constructor">
35 <title>Zend_Soap_Server constructor</title>
38 <classname>Zend_Soap_Server</classname> constructor should be used a bit differently for
39 WSDL and non-WSDL modes.
42 <sect3 id="zend.soap.server.constructor.wsdl_mode">
43 <title>Zend_Soap_Server constructor for the WSDL mode</title>
46 <classname>Zend_Soap_Server</classname> constructor takes two optional parameters
47 when it works in WSDL mode:
52 <varname>$wsdl</varname>, which is an <acronym>URI</acronym> of a WSDL
57 May be set later using <methodname>setWsdl($wsdl)</methodname>
66 <varname>$options</varname> - options to create <acronym>SOAP</acronym>
71 Options may be set later using
72 <methodname>setOptions($options)</methodname> method.
78 The following options are recognized in the WSDL mode:
83 'soap_version' ('soapVersion') - soap version to use
84 (SOAP_1_1 or <acronym>SOAP</acronym>_1_2).
90 'actor' - the actor <acronym>URI</acronym> for the server.
96 'classmap' ('classMap') which can be used to map some WSDL
97 types to <acronym>PHP</acronym> classes.
101 The option must be an array with WSDL types as keys and
102 names of <acronym>PHP</acronym> classes as values.
108 'encoding' - internal character encoding (UTF-8 is always
109 used as an external encoding).
115 'wsdl' which is equivalent to
116 <methodname>setWsdl($wsdlValue)</methodname> call.
126 <sect3 id="zend.soap.server.wsdl_mode">
127 <title>Zend_Soap_Server constructor for the non-WSDL mode</title>
130 The first constructor parameter <emphasis>must</emphasis> be set to
131 <constant>NULL</constant> if you plan to use <classname>Zend_Soap_Server</classname>
132 functionality in non-WSDL mode.
136 You also have to set 'uri' option in this case (see below).
140 The second constructor parameter (<varname>$options</varname>) is an array with
141 options to create <acronym>SOAP</acronym> server object
145 Options may be set later using <methodname>setOptions($options)</methodname>
152 The following options are recognized in the non-WSDL mode:
157 'soap_version' ('soapVersion') - soap version to use (SOAP_1_1 or
158 <acronym>SOAP</acronym>_1_2).
164 'actor' - the actor <acronym>URI</acronym> for the server.
170 'classmap' ('classMap') which can be used to map some WSDL types to
171 <acronym>PHP</acronym> classes.
175 The option must be an array with WSDL types as keys and names of
176 <acronym>PHP</acronym> classes as values.
182 'encoding' - internal character encoding (UTF-8 is always used as an
189 'uri' (required) - <acronym>URI</acronym> namespace for
190 <acronym>SOAP</acronym> server.
198 <sect2 id="zend.soap.server.api_define_methods">
199 <title>Methods to define Web Service API</title>
202 There are two ways to define Web Service <acronym>API</acronym> when your want to give
203 access to your <acronym>PHP</acronym> code through <acronym>SOAP</acronym>.
207 The first one is to attach some class to the <classname>Zend_Soap_Server</classname>
208 object which has to completely describe Web Service <acronym>API</acronym>:
211 <programlisting language="php"><![CDATA[
215 * This method takes ...
217 * @param integer $inputParam
220 public function method1($inputParam) {
225 * This method takes ...
227 * @param integer $inputParam1
228 * @param string $inputParam2
231 public function method2($inputParam1, $inputParam2) {
238 $server = new Zend_Soap_Server(null, $options);
239 // Bind Class to Soap Server
240 $server->setClass('MyClass');
241 // Bind already initialized object to Soap Server
242 $server->setObject(new MyClass());
248 <title>Important!</title>
251 You should completely describe each method using method docblock if you plan to
252 use autodiscover functionality to prepare corresponding Web Service WSDL.
257 The second method of defining Web Service <acronym>API</acronym> is using set of
258 functions and <methodname>addFunction()</methodname> or
259 <methodname>loadFunctions()</methodname> methods:
262 <programlisting language="php"><![CDATA[
267 * @param integer $inputParam
270 function function1($inputParam) {
277 * @param integer $inputParam1
278 * @param string $inputParam2
281 function function2($inputParam1, $inputParam2) {
285 $server = new Zend_Soap_Server(null, $options);
286 $server->addFunction('function1');
287 $server->addFunction('function2');
293 <sect2 id="zend.soap.server.request_response">
294 <title>Request and response objects handling</title>
297 <title>Advanced</title>
300 This section describes advanced request/response processing options and may be
306 <classname>Zend_Soap_Server</classname> component performs request/response processing
307 automatically, but allows to catch it and do some pre- and post-processing.
310 <sect3 id="zend.soap.server.request_response.request">
311 <title>Request processing</title>
314 <methodname>Zend_Soap_Server::handle()</methodname> method takes request from the
315 standard input stream ('php://input'). It may be overridden either by supplying
316 optional parameter to the <methodname>handle()</methodname> method or by setting
317 request using <methodname>setRequest()</methodname> method:
320 <programlisting language="php"><![CDATA[
322 $server = new Zend_Soap_Server(...);
324 // Set request using optional $request parameter
325 $server->handle($request);
327 // Set request using setRequest() method
328 $server->setRequest();
333 Request object may be represented using any of the following:
338 DOMDocument (casted to <acronym>XML</acronym>)
344 DOMNode (owner document is grabbed and casted to <acronym>XML</acronym>)
350 SimpleXMLElement (casted to <acronym>XML</acronym>)
356 stdClass (__toString() is called and verified to be valid
357 <acronym>XML</acronym>)
363 string (verified to be valid <acronym>XML</acronym>)
370 Last processed request may be retrieved using
371 <methodname>getLastRequest()</methodname> method as an <acronym>XML</acronym>
375 <programlisting language="php"><![CDATA[
377 $server = new Zend_Soap_Server(...);
380 $request = $server->getLastRequest();
384 <sect3 id="zend.soap.server.request_response.response">
385 <title>Response pre-processing</title>
388 <methodname>Zend_Soap_Server::handle()</methodname> method automatically emits
389 generated response to the output stream. It may be blocked using
390 <methodname>setReturnResponse()</methodname> with <constant>TRUE</constant> or
391 <constant>FALSE</constant> as a parameter
395 Current state of the Return Response flag may be requested with
396 <methodname>setReturnResponse()</methodname> method.
400 Generated response is returned by <methodname>handle()</methodname> method in this
404 <programlisting language="php"><![CDATA[
406 $server = new Zend_Soap_Server(...);
408 // Get a response as a return value of handle() method
409 // instead of emitting it to the standard output
410 $server->setReturnResponse(true);
412 $response = $server->handle();
417 Last response may be also retrieved by <methodname>getLastResponse()</methodname>
418 method for some post-processing:
421 <programlisting language="php"><![CDATA[
423 $server = new Zend_Soap_Server(...);
426 $response = $server->getLastResponse();