Zend_Soap_Client.xml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.soap.client">
  4. <title>Zend_Soap_Client</title>
  5. <para>
  6. The <classname>Zend_Soap_Client</classname> class simplifies SOAP client development for PHP programmers.
  7. </para>
  8. <para>
  9. It may be used in WSDL or non-WSDL mode.
  10. </para>
  11. <para>
  12. Under the WSDL mode, the Zend_Soap_Client component uses a WSDL document to define transport
  13. layer options.
  14. </para>
  15. <para>
  16. The WSDL description is usually provided by the web service the client will access. If the WSDL description is not
  17. made available, you may want to use Zend_Soap_Client in non-WSDL mode.
  18. Under this mode, all SOAP protocol options have to be set explicitly on the Zend_Soap_Client class.
  19. </para>
  20. <sect2 id="zend.soap.client.constructor">
  21. <title>Zend_Soap_Client Constructor</title>
  22. <para>
  23. The <classname>Zend_Soap_Client</classname> constructor takes two parameters:
  24. <itemizedlist>
  25. <listitem>
  26. <para>
  27. <code>$wsdl</code> - the URI of a WSDL file.
  28. </para>
  29. </listitem>
  30. <listitem>
  31. <para>
  32. <code>$options</code> - options to create SOAP client object.
  33. </para>
  34. </listitem>
  35. </itemizedlist>
  36. Both of these parameters may be set later using <code>setWsdl($wsdl)</code> and
  37. <code>setOptions($options)</code> methods respectively.
  38. </para>
  39. <note>
  40. <title>Important!</title>
  41. <para>
  42. If you use Zend_Soap_Client component in non-WSDL mode, you <emphasis>must</emphasis> set
  43. the 'location' and 'uri' options.
  44. </para>
  45. </note>
  46. <para>
  47. The following options are recognized:
  48. <itemizedlist>
  49. <listitem>
  50. <para>
  51. 'soap_version' ('soapVersion') - soap version to use (SOAP_1_1 or SOAP_1_2).
  52. </para>
  53. </listitem>
  54. <listitem>
  55. <para>
  56. 'classmap' ('classMap') - can be used to map some WSDL types to PHP classes.
  57. </para>
  58. <para>
  59. The option must be an array with WSDL types as keys and names of PHP classes as values.
  60. </para>
  61. </listitem>
  62. <listitem>
  63. <para>
  64. 'encoding' - internal character encoding (UTF-8 is always used as an external encoding).
  65. </para>
  66. </listitem>
  67. <listitem>
  68. <para>
  69. 'wsdl' which is equivalent to <code>setWsdl($wsdlValue)</code> call.
  70. </para>
  71. <para>
  72. Changing this option may switch Zend_Soap_Client object to or from WSDL mode.
  73. </para>
  74. </listitem>
  75. <listitem>
  76. <para>
  77. 'uri' - target namespace for the SOAP service (required for non-WSDL-mode, doesn't work for WSDL mode).
  78. </para>
  79. </listitem>
  80. <listitem>
  81. <para>
  82. 'location' - the URL to request (required for non-WSDL-mode, doesn't work for WSDL mode).
  83. </para>
  84. </listitem>
  85. <listitem>
  86. <para>
  87. 'style' - request style (doesn't work for WSDL mode): <code>SOAP_RPC</code> or <code>SOAP_DOCUMENT</code>.
  88. </para>
  89. </listitem>
  90. <listitem>
  91. <para>
  92. 'use' - method to encode messages (doesn't work for WSDL mode): <code>SOAP_ENCODED</code> or
  93. <code>SOAP_LITERAL</code>.
  94. </para>
  95. </listitem>
  96. <listitem>
  97. <para>
  98. 'login' and 'password' - login and password for an HTTP authentication.
  99. </para>
  100. </listitem>
  101. <listitem>
  102. <para>
  103. 'proxy_host', 'proxy_port', 'proxy_login', and 'proxy_password' - an HTTP connection through a proxy server.
  104. </para>
  105. </listitem>
  106. <listitem>
  107. <para>
  108. 'local_cert' and 'passphrase' - HTTPS client certificate authentication options.
  109. </para>
  110. </listitem>
  111. <listitem>
  112. <para>
  113. 'compression' - compression options; it's a combination of <code>SOAP_COMPRESSION_ACCEPT</code>,
  114. <code>SOAP_COMPRESSION_GZIP</code> and <code>SOAP_COMPRESSION_DEFLATE</code> options which
  115. may be used like this:
  116. <programlisting language="php"><![CDATA[
  117. // Accept response compression
  118. $client = new Zend_Soap_Client("some.wsdl",
  119. array('compression' => SOAP_COMPRESSION_ACCEPT));
  120. ...
  121. // Compress requests using gzip with compression level 5
  122. $client = new Zend_Soap_Client("some.wsdl",
  123. array('compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5));
  124. ...
  125. // Compress requests using deflate compression
  126. $client = new Zend_Soap_Client("some.wsdl",
  127. array('compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_DEFLATE));
  128. ]]></programlisting>
  129. </para>
  130. </listitem>
  131. </itemizedlist>
  132. </para>
  133. </sect2>
  134. <sect2 id="zend.soap.client.calls">
  135. <title>Performing SOAP Requests</title>
  136. <para>
  137. After we've created a <classname>Zend_Soap_Client</classname> object we are ready to perform SOAP requests.
  138. </para>
  139. <para>
  140. Each web service method is mapped to the virtual <classname>Zend_Soap_Client</classname> object method which takes
  141. parameters with common PHP types.
  142. </para>
  143. <para>
  144. Use it like in the following example:
  145. <programlisting language="php"><![CDATA[
  146. //****************************************************************
  147. // Server code
  148. //****************************************************************
  149. // class MyClass {
  150. // /**
  151. // * This method takes ...
  152. // *
  153. // * @param integer $inputParam
  154. // * @return string
  155. // */
  156. // public function method1($inputParam) {
  157. // ...
  158. // }
  159. //
  160. // /**
  161. // * This method takes ...
  162. // *
  163. // * @param integer $inputParam1
  164. // * @param string $inputParam2
  165. // * @return float
  166. // */
  167. // public function method2($inputParam1, $inputParam2) {
  168. // ...
  169. // }
  170. //
  171. // ...
  172. // }
  173. // ...
  174. // $server = new Zend_Soap_Server(null, $options);
  175. // $server->setClass('MyClass');
  176. // ...
  177. // $server->handle();
  178. //
  179. //****************************************************************
  180. // End of server code
  181. //****************************************************************
  182. $client = new Zend_Soap_Client("MyService.wsdl");
  183. ...
  184. // $result1 is a string
  185. $result1 = $client->method1(10);
  186. ...
  187. // $result2 is a float
  188. $result2 = $client->method2(22, 'some string');
  189. ]]></programlisting>
  190. </para>
  191. </sect2>
  192. </sect1>