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.
The Zend\Soap\Client constructor takes two parameters:
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 | // 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));
|
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 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | //****************************************************************
// 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');
|
The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.