Zend_Soap_Wsdl.xml 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.soap.wsdl">
  4. <title>WSDL Accessor</title>
  5. <note>
  6. <para>
  7. <classname>Zend_Soap_Wsdl</classname> class is used by
  8. <classname>Zend_Soap_Server</classname> component internally to operate with WSDL
  9. documents. Nevertheless, you could also use functionality provided by this class for
  10. your own needs. The <classname>Zend_Soap_Wsdl</classname> package contains both a parser
  11. and a builder of WSDL documents.
  12. </para>
  13. <para>
  14. If you don't plan to do this, you can skip this documentation section.
  15. </para>
  16. </note>
  17. <sect2 id="zend.soap.wsdl.constructor">
  18. <title>Zend_Soap_Wsdl constructor</title>
  19. <para>
  20. <classname>Zend_Soap_Wsdl</classname> constructor takes three parameters:
  21. <orderedlist>
  22. <listitem>
  23. <simpara>
  24. <varname>$name</varname> - name of the Web Service being described.
  25. </simpara>
  26. </listitem>
  27. <listitem>
  28. <simpara>
  29. <varname>$uri</varname> - <acronym>URI</acronym> where the WSDL will be
  30. available (could also be a reference to the file in the filesystem.)
  31. </simpara>
  32. </listitem>
  33. <listitem>
  34. <simpara>
  35. <varname>$strategy</varname> - optional flag used to identify the strategy
  36. for complex types (objects) detection. This was a boolean
  37. <varname>$extractComplexTypes</varname> before version 1.7 and can still be
  38. set as a boolean for backwards compatibility. By default the 1.6 detection
  39. behaviour is set. To read more on complex type detection strategies go to
  40. the section: <xref linkend="zend.soap.wsdl.types.add_complex" />.
  41. </simpara>
  42. </listitem>
  43. </orderedlist>
  44. </para>
  45. </sect2>
  46. <sect2 id="zend.soap.wsdl.addmessage">
  47. <title>addMessage() method</title>
  48. <para>
  49. <methodname>addMessage($name, $parts)</methodname> method adds new message description
  50. to the WSDL document (/definitions/message element).
  51. </para>
  52. <para>
  53. Each message correspond to methods in terms of <classname>Zend_Soap_Server</classname>
  54. and <classname>Zend_Soap_Client</classname> functionality.
  55. </para>
  56. <para>
  57. <varname>$name</varname> parameter represents message name.
  58. </para>
  59. <para>
  60. <varname>$parts</varname> parameter is an array of message parts which describe
  61. <acronym>SOAP</acronym> call parameters. It's an associative array: 'part name' (SOAP
  62. call parameter name) =&gt; 'part type'.
  63. </para>
  64. <para>
  65. Type mapping management is performed using <methodname>addTypes()</methodname>,
  66. <methodname>addTypes()</methodname> and <methodname>addComplexType()</methodname>
  67. methods (see below).
  68. </para>
  69. <note>
  70. <para>
  71. Messages parts can use either 'element' or 'type' attribute for typing
  72. (see <ulink url="http://www.w3.org/TR/wsdl#_messages"/>).
  73. </para>
  74. <para>
  75. 'element' attribute must refer to a corresponding element of data type definition.
  76. 'type' attribute refers to a corresponding complexType entry.
  77. </para>
  78. <para>
  79. All standard XSD types have both 'element' and 'complexType' definitions
  80. (see <ulink url="http://schemas.xmlsoap.org/soap/encoding/"/>).
  81. </para>
  82. <para>
  83. All non-standard types, which may be added using
  84. <methodname>Zend_Soap_Wsdl::addComplexType()</methodname> method, are described
  85. using 'complexType' node of '/definitions/types/schema/' section of WSDL document.
  86. </para>
  87. <para>
  88. So <methodname>addMessage()</methodname> method always uses 'type' attribute to
  89. describe types.
  90. </para>
  91. </note>
  92. </sect2>
  93. <sect2 id="zend.soap.wsdl.add_port_type">
  94. <title>addPortType() method</title>
  95. <para>
  96. <methodname>addPortType($name)</methodname> method adds new port type to the WSDL
  97. document (/definitions/portType) with the specified port type name.
  98. </para>
  99. <para>
  100. It joins a set of Web Service methods defined in terms of
  101. <classname>Zend_Soap_Server</classname> implementation.
  102. </para>
  103. <para>
  104. See <ulink url="http://www.w3.org/TR/wsdl#_porttypes"/> for the details.
  105. </para>
  106. </sect2>
  107. <sect2 id="zend.soap.wsdl.add_port_operation">
  108. <title>addPortOperation() method</title>
  109. <para>
  110. <methodname>addPortOperation($portType, $name, $input = false, $output = false, $fault
  111. = false)</methodname> method adds new port operation to the specified port type of
  112. the WSDL document (/definitions/portType/operation).
  113. </para>
  114. <para>
  115. Each port operation corresponds to a class method (if Web Service is based on a class)
  116. or function (if Web Service is based on a set of methods) in terms of
  117. <classname>Zend_Soap_Server</classname> implementation.
  118. </para>
  119. <para>
  120. It also adds corresponding port operation messages depending on specified
  121. <varname>$input</varname>, <varname>$output</varname> and <varname>$fault</varname>
  122. parameters.
  123. <note>
  124. <para>
  125. <classname>Zend_Soap_Server</classname> component generates two messages for
  126. each port operation while describing service based on
  127. <classname>Zend_Soap_Server</classname> class:
  128. <itemizedlist>
  129. <listitem>
  130. <para>
  131. input message with name <code>$methodName . 'Request'</code>.
  132. </para>
  133. </listitem>
  134. <listitem>
  135. <para>
  136. output message with name <code>$methodName . 'Response'</code>.
  137. </para>
  138. </listitem>
  139. </itemizedlist>
  140. </para>
  141. </note>
  142. </para>
  143. <para>
  144. See <ulink url="http://www.w3.org/TR/wsdl#_request-response"/> for the details.
  145. </para>
  146. </sect2>
  147. <sect2 id="zend.soap.wsdl.add_binding">
  148. <title>addBinding() method</title>
  149. <para>
  150. <methodname>addBinding($name, $portType)</methodname> method adds new binding to the
  151. WSDL document (/definitions/binding).
  152. </para>
  153. <para>
  154. 'binding' WSDL document node defines message format and protocol details for operations
  155. and messages defined by a particular portType (see <ulink
  156. url="http://www.w3.org/TR/wsdl#_bindings"/>).
  157. </para>
  158. <para>
  159. The method creates binding node and returns it. Then it may be used to fill with actual
  160. data.
  161. </para>
  162. <para>
  163. <classname>Zend_Soap_Server</classname> implementation uses
  164. <code>$serviceName . 'Binding'</code> name for 'binding' element of WSDL document.
  165. </para>
  166. </sect2>
  167. <sect2 id="zend.soap.wsdl.add_binding_operation">
  168. <title>addBindingOperation() method</title>
  169. <para>
  170. <methodname>addBindingOperation($binding, $name, $input = false, $output = false, $fault
  171. = false)</methodname> method adds an operation to a binding element
  172. (/definitions/binding/operation) with the specified name.
  173. </para>
  174. <para>
  175. It takes <code>XML_Tree_Node</code> object returned by
  176. <methodname>addBinding()</methodname> as an input (<varname>$binding</varname>
  177. parameter) to add 'operation' element with input/output/false entries depending on
  178. specified parameters
  179. </para>
  180. <para>
  181. <classname>Zend_Soap_Server</classname> implementation adds corresponding binding entry
  182. for each Web Service method with input and output entries defining 'soap:body' element
  183. as '&lt;soap:body use="encoded"
  184. encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/&gt;
  185. </para>
  186. <para>
  187. See <ulink url="http://www.w3.org/TR/wsdl#_bindings"/> for the details.
  188. </para>
  189. </sect2>
  190. <sect2 id="zend.soap.wsdl.add_soap_binding">
  191. <title>addSoapBinding() method</title>
  192. <para>
  193. <methodname>addSoapBinding($binding, $style = 'document', $transport =
  194. 'http://schemas.xmlsoap.org/soap/http')</methodname> method adds
  195. <acronym>SOAP</acronym> binding ('soap:binding') entry to the binding element (which is
  196. already linked to some port type) with the specified style and transport
  197. (Zend_Soap_Server implementation uses RPC style over <acronym>HTTP</acronym>).
  198. </para>
  199. <para>
  200. '/definitions/binding/soap:binding' element is used to signify that the binding is bound
  201. to the <acronym>SOAP</acronym> protocol format.
  202. </para>
  203. <para>
  204. See <ulink url="http://www.w3.org/TR/wsdl#_bindings"/> for the details.
  205. </para>
  206. </sect2>
  207. <sect2 id="zend.soap.wsdl.add_soap_operation">
  208. <title>addSoapOperation() method</title>
  209. <para>
  210. <methodname>addSoapOperation($binding, $soap_action)</methodname> method adds
  211. <acronym>SOAP</acronym> operation ('soap:operation') entry to the binding element with
  212. the specified action. 'style' attribute of the 'soap:operation' element is not used
  213. since programming model (RPC-oriented or document-oriented) may be using
  214. <methodname>addSoapBinding()</methodname> method
  215. </para>
  216. <para>
  217. 'soapAction' attribute of '/definitions/binding/soap:operation' element specifies the
  218. value of the <acronym>SOAP</acronym>Action header for this operation. This attribute is
  219. required for <acronym>SOAP</acronym> over <acronym>HTTP</acronym> and
  220. <emphasis>must not</emphasis> be specified for other transports.
  221. </para>
  222. <para>
  223. <classname>Zend_Soap_Server</classname> implementation uses
  224. <code>$serviceUri . '#' . $methodName</code> for <acronym>SOAP</acronym> operation
  225. action name.
  226. </para>
  227. <para>
  228. See <ulink url="http://www.w3.org/TR/wsdl#_soap:operation"/> for the details.
  229. </para>
  230. </sect2>
  231. <sect2 id="zend.soap.wsdl.add_service">
  232. <title>addService() method</title>
  233. <para>
  234. <methodname>addService($name, $port_name, $binding, $location)</methodname> method adds
  235. '/definitions/service' element to the WSDL document with the specified Wed Service name,
  236. port name, binding, and location.
  237. </para>
  238. <para>
  239. WSDL 1.1 allows to have several port types (sets of operations) per service. This
  240. ability is not used by <classname>Zend_Soap_Server</classname> implementation and not
  241. supported by <classname>Zend_Soap_Wsdl</classname> class.
  242. </para>
  243. <para>
  244. <classname>Zend_Soap_Server</classname> implementation uses:
  245. <itemizedlist>
  246. <listitem>
  247. <para>
  248. <code>$name . 'Service'</code> as a Web Service name,
  249. </para>
  250. </listitem>
  251. <listitem>
  252. <para>
  253. <code>$name . 'Port'</code> as a port type name,
  254. </para>
  255. </listitem>
  256. <listitem>
  257. <para>
  258. <code>'tns:' . $name . 'Binding'</code>
  259. <footnote>
  260. <para>
  261. <code>'tns:' namespace</code> is defined as script
  262. <acronym>URI</acronym> (<code>'http://' .$_SERVER['HTTP_HOST']
  263. . $_SERVER['SCRIPT_NAME']</code>).
  264. </para>
  265. </footnote>
  266. as binding name,
  267. </para>
  268. </listitem>
  269. <listitem>
  270. <para>
  271. script <acronym>URI</acronym>
  272. <footnote>
  273. <para>
  274. <code>'http://' .$_SERVER['HTTP_HOST'] .
  275. $_SERVER['SCRIPT_NAME']</code>
  276. </para>
  277. </footnote>
  278. as a service URI for Web Service definition using classes.
  279. </para>
  280. </listitem>
  281. </itemizedlist>
  282. where <varname>$name</varname> is a class name for the Web Service definition mode using
  283. class and script name for the Web Service definition mode using set of functions.
  284. </para>
  285. <para>
  286. See <ulink url="http://www.w3.org/TR/wsdl#_services"/> for the details.
  287. </para>
  288. </sect2>
  289. <sect2 id="zend.soap.wsdl.types">
  290. <title>Type mapping</title>
  291. <para>
  292. <classname>Zend_Soap</classname> WSDL accessor implementation uses the following type
  293. mapping between <acronym>PHP</acronym> and <acronym>SOAP</acronym> types:
  294. <itemizedlist>
  295. <listitem>
  296. <para>PHP strings &lt;-&gt; <code>xsd:string</code>.</para>
  297. </listitem>
  298. <listitem>
  299. <para>PHP integers &lt;-&gt; <code>xsd:int</code>.</para>
  300. </listitem>
  301. <listitem>
  302. <para>PHP floats and doubles &lt;-&gt; <code>xsd:float</code>.</para>
  303. </listitem>
  304. <listitem>
  305. <para>PHP booleans &lt;-&gt; <code>xsd:boolean</code>.</para>
  306. </listitem>
  307. <listitem>
  308. <para>PHP arrays &lt;-&gt; <code>soap-enc:Array</code>.</para>
  309. </listitem>
  310. <listitem>
  311. <para>PHP object &lt;-&gt; <code>xsd:struct</code>.</para>
  312. </listitem>
  313. <listitem>
  314. <para>
  315. <acronym>PHP</acronym> class &lt;-&gt; based on complex type strategy (See:
  316. <xref linkend="zend.soap.wsdl.types.add_complex" />)
  317. <footnote>
  318. <para>
  319. By default <classname>Zend_Soap_Wsdl</classname> will be created
  320. with the
  321. <classname>Zend_Soap_Wsdl_Strategy_DefaultComplexType</classname>
  322. class as detection algorithm for complex types. The first parameter
  323. of the AutoDiscover constructor takes any complex type strategy
  324. implementing
  325. <classname>Zend_Soap_Wsdl_Strategy_Interface</classname> or a string
  326. with the name of the class. For backwards compatibility with
  327. <varname>$extractComplexType</varname> boolean variables are parsed
  328. the following way: If <constant>TRUE</constant>,
  329. <classname>Zend_Soap_Wsdl_Strategy_DefaultComplexType</classname>,
  330. if <constant>FALSE</constant>
  331. <classname>Zend_Soap_Wsdl_Strategy_AnyType</classname>.
  332. </para>
  333. </footnote>.
  334. </para>
  335. </listitem>
  336. <listitem>
  337. <para>PHP void &lt;-&gt; empty type.</para>
  338. </listitem>
  339. <listitem>
  340. <para>
  341. If type is not matched to any of these types by some reason, then
  342. <code>xsd:anyType</code> is used.
  343. </para>
  344. </listitem>
  345. </itemizedlist>
  346. Where <code>xsd:</code> is "http://www.w3.org/2001/XMLSchema" namespace,
  347. <code>soap-enc:</code> is a "http://schemas.xmlsoap.org/soap/encoding/" namespace,
  348. <code>tns:</code> is a "target namespace" for a service.
  349. </para>
  350. <sect3 id="zend.soap.wsdl.types.retrieve">
  351. <title>Retrieving type information</title>
  352. <para>
  353. <methodname>getType($type)</methodname> method may be used to get mapping for a
  354. specified <acronym>PHP</acronym> type:
  355. <programlisting language="php"><![CDATA[
  356. ...
  357. $wsdl = new Zend_Soap_Wsdl('My_Web_Service', $myWebServiceUri);
  358. ...
  359. $soapIntType = $wsdl->getType('int');
  360. ...
  361. class MyClass {
  362. ...
  363. }
  364. ...
  365. $soapMyClassType = $wsdl->getType('MyClass');
  366. ]]></programlisting>
  367. </para>
  368. </sect3>
  369. <sect3 id="zend.soap.wsdl.types.add_complex">
  370. <title>Adding complex type information</title>
  371. <para>
  372. <methodname>addComplexType($type)</methodname> method is used to add complex types
  373. (PHP classes) to a WSDL document.
  374. </para>
  375. <para>
  376. It's automatically used by <methodname>getType()</methodname> method to add
  377. corresponding complex types of method parameters or return types.
  378. </para>
  379. <para>
  380. Its detection and building algorithm is based on the currently active detection
  381. strategy for complex types. You can set the detection strategy either by specifying
  382. the class name as string or instance of a
  383. <classname>Zend_Soap_Wsdl_Strategy_Interface</classname> implementation as the third
  384. parameter of the constructor or using the
  385. <methodname>setComplexTypeStrategy($strategy)</methodname> function of
  386. <classname>Zend_Soap_Wsdl</classname>. The following detection strategies currently
  387. exist:
  388. </para>
  389. <itemizedlist>
  390. <listitem>
  391. <para>
  392. Class <classname>Zend_Soap_Wsdl_Strategy_DefaultComplexType</classname>:
  393. Enabled by default (when no third constructor parameter is set). Iterates
  394. over the public attributes of a class type and registers them as subtypes of
  395. the complex object type.
  396. </para>
  397. </listitem>
  398. <listitem>
  399. <para>
  400. Class <classname>Zend_Soap_Wsdl_Strategy_AnyType</classname>: Casts all
  401. complex types into the simple XSD type xsd:anyType. Be careful this shortcut
  402. for complex type detection can probably only be handled successfully by
  403. weakly typed languages such as <acronym>PHP</acronym>.
  404. </para>
  405. </listitem>
  406. <listitem>
  407. <para>
  408. Class <classname>Zend_Soap_Wsdl_Strategy_ArrayOfTypeSequence</classname>:
  409. This strategy allows to specify return parameters of the type:
  410. <code>int[]</code> or <code>string[]</code>. As of Zend Framework version
  411. 1.9 it can handle both simple <acronym>PHP</acronym> types such as int,
  412. string, boolean, float aswell as objects and arrays of objects.
  413. </para>
  414. </listitem>
  415. <listitem>
  416. <para>
  417. Class <classname>Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex</classname>:
  418. This strategy allows to detect very complex arrays of objects. Objects types
  419. are detected based on the
  420. <classname>Zend_Soap_Wsdl_Strategy_DefaultComplexType</classname> and an
  421. array is wrapped around that definition.
  422. </para>
  423. </listitem>
  424. <listitem>
  425. <para>
  426. Class <classname>Zend_Soap_Wsdl_Strategy_Composite</classname>: This
  427. strategy can combine all strategies by connecting <acronym>PHP</acronym>
  428. Complex types (Classnames) to the desired strategy via the
  429. <methodname>connectTypeToStrategy($type, $strategy)</methodname> method. A
  430. complete typemap can be given to the constructor as an array with
  431. <varname>$type</varname> -> <varname>$strategy</varname> pairs. The second
  432. parameter specifies the default strategy that will be used if an unknown
  433. type is requested for adding. This parameter defaults to the
  434. <classname>Zend_Soap_Wsdl_Strategy_DefaultComplexType</classname> strategy.
  435. </para>
  436. </listitem>
  437. </itemizedlist>
  438. <para>
  439. <methodname>addComplexType()</methodname> method creates
  440. '/definitions/types/xsd:schema/xsd:complexType' element for
  441. each described complex type with name of the specified <acronym>PHP</acronym> class.
  442. </para>
  443. <para>
  444. Class property <emphasis>MUST</emphasis> have docblock section with the described
  445. <acronym>PHP</acronym> type to have property included into WSDL description.
  446. </para>
  447. <para>
  448. <methodname>addComplexType()</methodname> checks if type is already described within
  449. types section of the WSDL document.
  450. </para>
  451. <para>
  452. It prevents duplications if this method is called two or more times and recursion in
  453. the types definition section.
  454. </para>
  455. <para>
  456. See <ulink url="http://www.w3.org/TR/wsdl#_types"/> for the details.
  457. </para>
  458. </sect3>
  459. </sect2>
  460. <sect2 id="zend.soap.wsdl.add_documentation">
  461. <title>addDocumentation() method</title>
  462. <para>
  463. <methodname>addDocumentation($input_node, $documentation)</methodname> method adds human
  464. readable documentation using optional 'wsdl:document' element.
  465. </para>
  466. <para>
  467. '/definitions/binding/soap:binding' element is used to signify that the binding is bound
  468. to the <acronym>SOAP</acronym> protocol format.
  469. </para>
  470. <para>
  471. See <ulink url="http://www.w3.org/TR/wsdl#_documentation"/> for the details.
  472. </para>
  473. </sect2>
  474. <sect2 id="zend.soap.wsdl.retrieve">
  475. <title>Get finalized WSDL document</title>
  476. <para>
  477. <methodname>toXML()</methodname>, <methodname>toDomDocument()</methodname> and
  478. <methodname>dump($filename = false)</methodname> methods may be used to get WSDL
  479. document as an <acronym>XML</acronym>, DOM structure or a file.
  480. </para>
  481. </sect2>
  482. </sect1>