Zend_Soap_Wsdl.xml 23 KB

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