Programmer's Reference Guide
| Zend_Soap_Server |
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.
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:
- // Accept response compression
- $client = new Zend_Soap_Client("some.wsdl",
- ...
- // Compress requests using gzip with compression level 5
- $client = new Zend_Soap_Client("some.wsdl",
- ...
- // Compress requests using deflate compression
- $client = new Zend_Soap_Client("some.wsdl",
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:
- //****************************************************************
- // 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');
| Zend_Soap_Server |
Add A Comment
Please do not report issues via comments; use the ZF Issue Tracker.
If you have a JIRA/Crowd account, we suggest you login first before commenting.

Comments
im trying to put this code to work but i get a exception when i run it, hope some one can help:
public function indexAction()
{
$client = new Zend_Soap_Client("http://www.27seconds.com/Holidays/US/Dates/USHolidayDates.asmx?WSDL", array('encoding' => 'UTF-8'));
$params = array('year'=>2010);
$result = $client->GetMemorialDay( $params );
echo $result->GetMemorialDayResult;
}
the web service is a valid WS, if you try to cosume it using php's SoapClient it works.
im trying to put this code to work but i get a exception when i run it, hope some one can help:
public function indexAction()
{
$client = new Zend_Soap_Client("http://www.27seconds.com/Holidays/US/Dates/USHolidayDates.asmx?WSDL", array('encoding' => 'UTF-8'));
$params = array('year'=>2010);
$result = $client->GetMemorialDay( $params );
echo $result->GetMemorialDayResult;
}
the web service is a valid WS, if you try to cosume it using php's SoapClient it works.
I have this exception when I'm running my code. It uses a Zend_Soap_Client.
PHP Fatal error: Uncaught SoapFault exception: [3001] Invalid Session in ...... Zend/Soap/Client.php on line 1113
Changing the soap_version back and forth did not work. The worst is that I have the exact same code on my localhost and it works. I checked the php settings and they are the same, but I guess I miss somethig. Any ideas? Thanks.
Application error
Exception information:
Message: SOAP extension is not loaded.
where my code is as follow:
public function indexAction()
{
$client = new Zend_Soap_Client('https://developer- api.affili.net/V2.0/PublisherInbox.svc?wsdl');
}
Please someone help in this regard and thanks in anticipation.
enable extension=php_soap.dll in php.in
class Eu_Vat_Checker {
/**
* VIES WDSL location
*/
const WDSL = 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService?wsdl'; //check before use, it could change
/**
* Check if valid VAT
*
* @param string $country (Like RO, HU)
* @param string $VAT (Like 123456)
* @return array
*
*/
public function check($country, $VAT)
{
$client = new Zend_Soap_Client(self::WDSL);
$params = array('countryCode' => $country,
'vatNumber' => $VAT);
try {
$result = $client->checkVat($params);
} catch (Exception $e) {
//Log exception here
return false;
}
return array(
'countryCode' => $result->countryCode,
'vatNumber' => $result->vatNumber,
'valid' => $result->valid,
'name' => $result->name,
'address' => $result->address
);
}
}
Although I'm able to return all the Functions and Types from the WSDL.
I have the same problem, but I know who is the problem...
The Host is the Endpoint of your WSDL.
If your WSDL have a bad URL in the tag Endpoint, you "throw" an exception.
But I have a Question... Is it possible to change the Endpoint with Zend?
For exemple you create your client Object, and you call a getWSDL and call a setEndPoint() function from the WSDL Object?
$oClient->getWsdl()->setEndPoint('http://pouloute.fr/poulouteWebService/');
Thanks!
<---------------------------------------------------------------->
$url = 'http://abc.com/somservice.asmx?wsdl';
$options = array("soap_version" => SOAP_1_1);
$client = new Zend_Soap_Client($url,$options);
var_dump($client->somefunction(
array(
"param1"=>"aaa",
"param2"=>"008",
"param3"=>"008",
"param4"=>"asdb",
"param5"=>"dd",
)
));
<---------------------------------------------------------------->
And i am getting a response like this
<---------------------------------------------------------------->
object(stdClass)#53 (1) { ["somefunctionResult"]=> object(stdClass)#54 (2) { ["schema"]=> string(552) "" ["any"]=> string(758) "TC488.92TH172TI973TR516" } }
<---------------------------------------------------------------->.
This seems like an object. How can i use it ?
How can i convert it to JSON? (Zend_Json Encode not returning proper data)
How can i convert it to XML ?