Zend_Soap_Wsdl.xml 23 KB

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