| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- Reviewed: no -->
- <sect1 id="zend.soap.client">
- <title>Zend_Soap_Client</title>
- <para>
- The <classname>Zend_Soap_Client</classname> class simplifies SOAP client development for PHP programmers.
- </para>
- <para>
- It may be used in WSDL or non-WSDL mode.
- </para>
- <para>
- Under the WSDL mode, the Zend_Soap_Client component uses a WSDL document to define transport
- layer options.
- </para>
- <para>
- The WSDL description is usually provided by the web service the client will access. If the WSDL description is not
- made available, you may want to use Zend_Soap_Client in non-WSDL mode.
- Under this mode, all SOAP protocol options have to be set explicitly on the Zend_Soap_Client class.
- </para>
- <sect2 id="zend.soap.client.constructor">
- <title>Zend_Soap_Client Constructor</title>
- <para>
- The <classname>Zend_Soap_Client</classname> constructor takes two parameters:
- <itemizedlist>
- <listitem>
- <para>
- <code>$wsdl</code> - the URI of a WSDL file.
- </para>
- </listitem>
- <listitem>
- <para>
- <code>$options</code> - options to create SOAP client object.
- </para>
- </listitem>
- </itemizedlist>
- Both of these parameters may be set later using <code>setWsdl($wsdl)</code> and
- <code>setOptions($options)</code> methods respectively.
- </para>
- <note>
- <title>Important!</title>
- <para>
- If you use Zend_Soap_Client component in non-WSDL mode, you <emphasis>must</emphasis> set
- the 'location' and 'uri' options.
- </para>
- </note>
- <para>
- The following options are recognized:
- <itemizedlist>
- <listitem>
- <para>
- 'soap_version' ('soapVersion') - soap version to use (SOAP_1_1 or SOAP_1_2).
- </para>
- </listitem>
- <listitem>
- <para>
- 'classmap' ('classMap') - can be used to map some WSDL types to PHP classes.
- </para>
- <para>
- The option must be an array with WSDL types as keys and names of PHP classes as values.
- </para>
- </listitem>
- <listitem>
- <para>
- 'encoding' - internal character encoding (UTF-8 is always used as an external encoding).
- </para>
- </listitem>
- <listitem>
- <para>
- 'wsdl' which is equivalent to <code>setWsdl($wsdlValue)</code> call.
- </para>
- <para>
- Changing this option may switch Zend_Soap_Client object to or from WSDL mode.
- </para>
- </listitem>
- <listitem>
- <para>
- 'uri' - target namespace for the SOAP service (required for non-WSDL-mode, doesn't work for WSDL mode).
- </para>
- </listitem>
- <listitem>
- <para>
- 'location' - the URL to request (required for non-WSDL-mode, doesn't work for WSDL mode).
- </para>
- </listitem>
- <listitem>
- <para>
- 'style' - request style (doesn't work for WSDL mode): <code>SOAP_RPC</code> or <code>SOAP_DOCUMENT</code>.
- </para>
- </listitem>
- <listitem>
- <para>
- 'use' - method to encode messages (doesn't work for WSDL mode): <code>SOAP_ENCODED</code> or
- <code>SOAP_LITERAL</code>.
- </para>
- </listitem>
- <listitem>
- <para>
- 'login' and 'password' - login and password for an HTTP authentication.
- </para>
- </listitem>
- <listitem>
- <para>
- 'proxy_host', 'proxy_port', 'proxy_login', and 'proxy_password' - an HTTP connection through a proxy server.
- </para>
- </listitem>
- <listitem>
- <para>
- 'local_cert' and 'passphrase' - HTTPS client certificate authentication options.
- </para>
- </listitem>
- <listitem>
- <para>
- 'compression' - compression options; it's a combination of <code>SOAP_COMPRESSION_ACCEPT</code>,
- <code>SOAP_COMPRESSION_GZIP</code> and <code>SOAP_COMPRESSION_DEFLATE</code> options which
- may be used like this:
- <programlisting language="php"><![CDATA[
- // Accept response compression
- $client = new Zend_Soap_Client("some.wsdl",
- array('compression' => SOAP_COMPRESSION_ACCEPT));
- ...
- // Compress requests using gzip with compression level 5
- $client = new Zend_Soap_Client("some.wsdl",
- array('compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5));
- ...
- // Compress requests using deflate compression
- $client = new Zend_Soap_Client("some.wsdl",
- array('compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_DEFLATE));
- ]]></programlisting>
- </para>
- </listitem>
- </itemizedlist>
- </para>
- </sect2>
- <sect2 id="zend.soap.client.calls">
- <title>Performing SOAP Requests</title>
- <para>
- After we've created a <classname>Zend_Soap_Client</classname> object we are ready to perform SOAP requests.
- </para>
- <para>
- Each web service method is mapped to the virtual <classname>Zend_Soap_Client</classname> object method which takes
- parameters with common PHP types.
- </para>
- <para>
- Use it like in the following example:
- <programlisting language="php"><![CDATA[
- //****************************************************************
- // Server code
- //****************************************************************
- // class MyClass {
- // /**
- // * This method takes ...
- // *
- // * @param integer $inputParam
- // * @return string
- // */
- // public function method1($inputParam) {
- // ...
- // }
- //
- // /**
- // * This method takes ...
- // *
- // * @param integer $inputParam1
- // * @param string $inputParam2
- // * @return float
- // */
- // public function method2($inputParam1, $inputParam2) {
- // ...
- // }
- //
- // ...
- // }
- // ...
- // $server = new Zend_Soap_Server(null, $options);
- // $server->setClass('MyClass');
- // ...
- // $server->handle();
- //
- //****************************************************************
- // End of server code
- //****************************************************************
- $client = new Zend_Soap_Client("MyService.wsdl");
- ...
- // $result1 is a string
- $result1 = $client->method1(10);
- ...
- // $result2 is a float
- $result2 = $client->method2(22, 'some string');
- ]]></programlisting>
- </para>
- </sect2>
- </sect1>
|