Zend_Soap_Wsdl.xml 24 KB

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