Zend_Soap_Client.xml 8.3 KB

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