Zend_Soap_Server.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.soap.server">
  4. <title>Zend_Soap_Server</title>
  5. <para>
  6. <classname>Zend_Soap_Server</classname> class is intended to simplify Web Services server
  7. part development for <acronym>PHP</acronym> programmers.
  8. </para>
  9. <para>
  10. It may be used in WSDL or non-WSDL mode, and using classes or functions to define Web
  11. Service <acronym>API</acronym>.
  12. </para>
  13. <para>
  14. When <classname>Zend_Soap_Server</classname> component works in the WSDL mode, it uses
  15. already prepared WSDL document to define server object behavior and transport layer options.
  16. </para>
  17. <para>
  18. WSDL document may be auto-generated with functionality provided by <link
  19. linkend="zend.soap.autodiscovery.introduction">Zend_Soap_AutoDiscovery component</link>
  20. or should be constructed manually using <link
  21. linkend="zend.soap.wsdl"><classname>Zend_Soap_Wsdl</classname> class</link> or any other
  22. <acronym>XML</acronym> generating tool.
  23. </para>
  24. <para>
  25. If the non-WSDL mode is used, then all protocol options have to be set using options
  26. mechanism.
  27. </para>
  28. <sect2 id="zend.soap.server.constructor">
  29. <title>Zend_Soap_Server constructor</title>
  30. <para>
  31. <classname>Zend_Soap_Server</classname> constructor should be used a bit differently for
  32. WSDL and non-WSDL modes.
  33. </para>
  34. <sect3 id="zend.soap.server.constructor.wsdl_mode">
  35. <title>Zend_Soap_Server constructor for the WSDL mode</title>
  36. <para>
  37. <classname>Zend_Soap_Server</classname> constructor takes two optional parameters
  38. when it works in WSDL mode:
  39. <orderedlist>
  40. <listitem>
  41. <para>
  42. <varname>$wsdl</varname>, which is an <acronym>URI</acronym> of a WSDL file
  43. <footnote>
  44. <para>
  45. May be set later using <methodname>setWsdl($wsdl)</methodname>
  46. method.
  47. </para>
  48. </footnote>.
  49. </para>
  50. </listitem>
  51. <listitem>
  52. <para>
  53. <varname>$options</varname> - options to create <acronym>SOAP</acronym>
  54. server object
  55. <footnote>
  56. <para>
  57. Options may be set later using
  58. <methodname>setOptions($options)</methodname> method.
  59. </para>
  60. </footnote>.
  61. </para>
  62. <para>
  63. The following options are recognized in the WSDL mode:
  64. <itemizedlist>
  65. <listitem>
  66. <para>
  67. 'soap_version' ('soapVersion') - soap version to use
  68. (SOAP_1_1 or <acronym>SOAP</acronym>_1_2).
  69. </para>
  70. </listitem>
  71. <listitem>
  72. <para>
  73. 'actor' - the actor <acronym>URI</acronym> for the server.
  74. </para>
  75. </listitem>
  76. <listitem>
  77. <para>
  78. 'classmap' ('classMap') which can be used to map some WSDL
  79. types to <acronym>PHP</acronym> classes.
  80. </para>
  81. <para>
  82. The option must be an array with WSDL types as keys and
  83. names of <acronym>PHP</acronym> classes as values.
  84. </para>
  85. </listitem>
  86. <listitem>
  87. <para>
  88. 'encoding' - internal character encoding (UTF-8 is always
  89. used as an external encoding).
  90. </para>
  91. </listitem>
  92. <listitem>
  93. <para>
  94. 'wsdl' which is equivalent to
  95. <methodname>setWsdl($wsdlValue)</methodname> call.
  96. </para>
  97. </listitem>
  98. </itemizedlist>
  99. </para>
  100. </listitem>
  101. </orderedlist>
  102. </para>
  103. </sect3>
  104. <sect3 id="zend.soap.server.wsdl_mode">
  105. <title>Zend_Soap_Server constructor for the non-WSDL mode</title>
  106. <para>
  107. The first constructor parameter <emphasis>must</emphasis> be set to
  108. <constant>NULL</constant> if you plan to use <classname>Zend_Soap_Server</classname>
  109. functionality in non-WSDL mode.
  110. </para>
  111. <para>
  112. You also have to set 'uri' option in this case (see below).
  113. </para>
  114. <para>
  115. The second constructor parameter (<varname>$options</varname>) is an array with
  116. options to create <acronym>SOAP</acronym> server object
  117. <footnote>
  118. <para>
  119. Options may be set later using <methodname>setOptions($options)</methodname>
  120. method.
  121. </para>
  122. </footnote>.
  123. </para>
  124. <para>
  125. The following options are recognized in the non-WSDL mode:
  126. <itemizedlist>
  127. <listitem>
  128. <para>
  129. 'soap_version' ('soapVersion') - soap version to use (SOAP_1_1 or
  130. <acronym>SOAP</acronym>_1_2).
  131. </para>
  132. </listitem>
  133. <listitem>
  134. <para>
  135. 'actor' - the actor <acronym>URI</acronym> for the server.
  136. </para>
  137. </listitem>
  138. <listitem>
  139. <para>
  140. 'classmap' ('classMap') which can be used to map some WSDL types to
  141. <acronym>PHP</acronym> classes.
  142. </para>
  143. <para>
  144. The option must be an array with WSDL types as keys and names of
  145. <acronym>PHP</acronym> classes as values.
  146. </para>
  147. </listitem>
  148. <listitem>
  149. <para>
  150. 'encoding' - internal character encoding (UTF-8 is always used as an
  151. external encoding).
  152. </para>
  153. </listitem>
  154. <listitem>
  155. <para>
  156. 'uri' (required) - <acronym>URI</acronym> namespace for
  157. <acronym>SOAP</acronym> server.
  158. </para>
  159. </listitem>
  160. </itemizedlist>
  161. </para>
  162. </sect3>
  163. </sect2>
  164. <sect2 id="zend.soap.server.api_define_methods">
  165. <title>Methods to define Web Service API</title>
  166. <para>
  167. There are two ways to define Web Service <acronym>API</acronym> when your want to give
  168. access to your <acronym>PHP</acronym> code through <acronym>SOAP</acronym>.
  169. </para>
  170. <para>
  171. The first one is to attach some class to the <classname>Zend_Soap_Server</classname>
  172. object which has to completely describe Web Service API:
  173. <programlisting language="php"><![CDATA[
  174. ...
  175. class MyClass {
  176. /**
  177. * This method takes ...
  178. *
  179. * @param integer $inputParam
  180. * @return string
  181. */
  182. public function method1($inputParam) {
  183. ...
  184. }
  185. /**
  186. * This method takes ...
  187. *
  188. * @param integer $inputParam1
  189. * @param string $inputParam2
  190. * @return float
  191. */
  192. public function method2($inputParam1, $inputParam2) {
  193. ...
  194. }
  195. ...
  196. }
  197. ...
  198. $server = new Zend_Soap_Server(null, $options);
  199. // Bind Class to Soap Server
  200. $server->setClass('MyClass');
  201. // Bind already initialized object to Soap Server
  202. $server->setObject(new MyClass());
  203. ...
  204. $server->handle();
  205. ]]></programlisting>
  206. <note>
  207. <title>Important!</title>
  208. <para>
  209. You should completely describe each method using method docblock if you plan to
  210. use autodiscover functionality to prepare corresponding Web Service WSDL.
  211. </para>
  212. </note>
  213. </para>
  214. <para>
  215. The second method of defining Web Service API is using set of functions and
  216. <methodname>addFunction()</methodname> or <methodname>loadFunctions()</methodname>
  217. methods:
  218. <programlisting language="php"><![CDATA[
  219. ...
  220. /**
  221. * This function ...
  222. *
  223. * @param integer $inputParam
  224. * @return string
  225. */
  226. function function1($inputParam) {
  227. ...
  228. }
  229. /**
  230. * This function ...
  231. *
  232. * @param integer $inputParam1
  233. * @param string $inputParam2
  234. * @return float
  235. */
  236. function function2($inputParam1, $inputParam2) {
  237. ...
  238. }
  239. ...
  240. $server = new Zend_Soap_Server(null, $options);
  241. $server->addFunction('function1');
  242. $server->addFunction('function2');
  243. ...
  244. $server->handle();
  245. ]]></programlisting>
  246. </para>
  247. </sect2>
  248. <sect2 id="zend.soap.server.request_response">
  249. <title>Request and response objects handling</title>
  250. <note>
  251. <title>Advanced</title>
  252. <para>
  253. This section describes advanced request/response processing options and may be
  254. skipped.
  255. </para>
  256. </note>
  257. <para>
  258. <classname>Zend_Soap_Server</classname> component performs request/response processing
  259. automatically, but allows to catch it and do some pre- and post-processing.
  260. </para>
  261. <sect3 id="zend.soap.server.request_response.request">
  262. <title>Request processing</title>
  263. <para>
  264. <methodname>Zend_Soap_Server::handle()</methodname> method takes request from the
  265. standard input stream ('php://input'). It may be overridden either by supplying
  266. optional parameter to the <methodname>handle()</methodname> method or by setting
  267. request using <methodname>setRequest()</methodname> method:
  268. <programlisting language="php"><![CDATA[
  269. ...
  270. $server = new Zend_Soap_Server(...);
  271. ...
  272. // Set request using optional $request parameter
  273. $server->handle($request);
  274. ...
  275. // Set request using setRequest() method
  276. $server->setRequest();
  277. $server->handle();
  278. ]]></programlisting>
  279. </para>
  280. <para>
  281. Request object may be represented using any of the following:
  282. <itemizedlist>
  283. <listitem>
  284. <para>
  285. DOMDocument (casted to <acronym>XML</acronym>)
  286. </para>
  287. </listitem>
  288. <listitem>
  289. <para>
  290. DOMNode (owner document is grabbed and casted to <acronym>XML</acronym>)
  291. </para>
  292. </listitem>
  293. <listitem>
  294. <para>
  295. SimpleXMLElement (casted to <acronym>XML</acronym>)
  296. </para>
  297. </listitem>
  298. <listitem>
  299. <para>
  300. stdClass (__toString() is called and verified to be valid
  301. <acronym>XML</acronym>)
  302. </para>
  303. </listitem>
  304. <listitem>
  305. <para>
  306. string (verified to be valid <acronym>XML</acronym>)
  307. </para>
  308. </listitem>
  309. </itemizedlist>
  310. </para>
  311. <para>
  312. Last processed request may be retrieved using
  313. <methodname>getLastRequest()</methodname> method as an XML string:
  314. <programlisting language="php"><![CDATA[
  315. ...
  316. $server = new Zend_Soap_Server(...);
  317. ...
  318. $server->handle();
  319. $request = $server->getLastRequest();
  320. ]]></programlisting>
  321. </para>
  322. </sect3>
  323. <sect3 id="zend.soap.server.request_response.response">
  324. <title>Response pre-processing</title>
  325. <para>
  326. <methodname>Zend_Soap_Server::handle()</methodname> method automatically emits
  327. generated response to the output stream. It may be blocked using
  328. <methodname>setReturnResponse()</methodname> with <constant>TRUE</constant> or
  329. <constant>FALSE</constant> as a parameter
  330. <footnote>
  331. <para>
  332. Current state of the Return Response flag may be requested with
  333. <methodname>setReturnResponse()</methodname> method.
  334. </para>
  335. </footnote>.
  336. Generated response is returned by <methodname>handle()</methodname> method in this
  337. case.
  338. <programlisting language="php"><![CDATA[
  339. ...
  340. $server = new Zend_Soap_Server(...);
  341. ...
  342. // Get a response as a return value of handle() method
  343. // instead of emitting it to the standard output
  344. $server->setReturnResponse(true);
  345. ...
  346. $response = $server->handle();
  347. ...
  348. ]]></programlisting>
  349. </para>
  350. <para>
  351. Last response may be also retrieved by <methodname>getLastResponse()</methodname>
  352. method for some post-processing:
  353. <programlisting language="php"><![CDATA[
  354. ...
  355. $server = new Zend_Soap_Server(...);
  356. ...
  357. $server->handle();
  358. $response = $server->getLastResponse();
  359. ...
  360. ]]></programlisting>
  361. </para>
  362. </sect3>
  363. </sect2>
  364. </sect1>