Zend_Soap_Server | Zend_Soap Programmer's Reference Guide | WSDL Accessor

# Zend_Soap_Client

The Zend_Soap_Client class simplifies SOAP client development for PHP programmers.

It may be used in WSDL or non-WSDL mode.

Under the WSDL mode, the Zend_Soap_Client component uses a WSDL document to define transport layer options.

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.

# Zend_Soap_Client Constructor

The Zend_Soap_Client constructor takes two parameters:

- $wsdl - the URI of a WSDL file.

- $options - options to create SOAP client object.

Both of these parameters may be set later using setWsdl($wsdl) and setOptions($options) methods respectively.

> Note: Important!
> If you use Zend_Soap_Client component in non-WSDL mode, you must set the 'location' and 'uri' options.

The following options are recognized:

- 'soap_version' ('soapVersion') - soap version to use (SOAP_1_1 or SOAP_1_2).

- 'classmap' ('classMap') - can be used to map some WSDL types to PHP classes.

  The option must be an array with WSDL types as keys and names of PHP classes as values.

- 'encoding' - internal character encoding (UTF-8 is always used as an external encoding).

- 'wsdl' which is equivalent to setWsdl($wsdlValue) call.

  Changing this option may switch Zend_Soap_Client object to or from WSDL mode.

- 'uri' - target namespace for the SOAP service (required for non-WSDL-mode, doesn't work for WSDL mode).

- 'location' - the URL to request (required for non-WSDL-mode, doesn't work for WSDL mode).

- 'style' - request style (doesn't work for WSDL mode): `SOAP_RPC` or `SOAP_DOCUMENT`.

- 'use' - method to encode messages (doesn't work for WSDL mode): `SOAP_ENCODED` or `SOAP_LITERAL`.

- 'login' and 'password' - login and password for an HTTP authentication.

- 'proxy_host', 'proxy_port', 'proxy_login', and 'proxy_password' - an HTTP connection through a proxy server.

- 'local_cert' and 'passphrase' - HTTPS client certificate authentication options.

- 'compression' - compression options; it's a combination of `SOAP_COMPRESSION_ACCEPT`, `SOAP_COMPRESSION_GZIP` and `SOAP_COMPRESSION_DEFLATE` options which may be used like this:

  1. // Accept response compression
  2. $client = new Zend_Soap_Client("some.wsdl",
  3. array ('compression' => SOAP_COMPRESSION_ACCEPT));
  4. ...
  6. // Compress requests using gzip with compression level 5
  7. $client = new Zend_Soap_Client("some.wsdl",
  8. array ('compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | 5));
  9. ...
  11. // Compress requests using deflate compression
  12. $client = new Zend_Soap_Client("some.wsdl",
  13. array ('compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_DEFLATE));

# Performing SOAP Requests

After we've created a Zend_Soap_Client object we are ready to perform SOAP requests.

Each web service method is mapped to the virtual Zend_Soap_Client object method which takes parameters with common PHP types.

Use it like in the following example:

1. //****************************************************************
2. // Server code
3. //****************************************************************
4. // class MyClass {
5. // /**
6. // * This method takes ...
7. // *
8. // * @param integer $inputParam
9. // * @return string
10. // */
11. // public function method1($inputParam) {
12. // ...
13. // }
14. //
15. // /**
16. // * This method takes ...
17. // *
18. // * @param integer $inputParam1
19. // * @param string $inputParam2
20. // * @return float
21. // */
22. // public function method2($inputParam1, $inputParam2) {
23. // ...
24. // }
25. //
26. // ...
27. // }
28. // ...
29. // $server = new Zend_Soap_Server(null, $options);
30. // $server->setClass('MyClass');
31. // ...
32. // $server->handle();
33. //
34. //****************************************************************
35. // End of server code
36. //****************************************************************
38. $client = new Zend_Soap_Client("MyService.wsdl");
39. ...
41. // $result1 is a string
42. $result1 = $client->method1(10);
43. ...
45. // $result2 is a float
46. $result2 = $client->method2(22, 'some string');

Zend_Soap_Server | Zend_Soap Programmer's Reference Guide | WSDL Accessor