SoapClient::__call

(PHP 5, PHP 7, PHP 8)

SoapClient::__callCalls a SOAP function (deprecated)

Açıklama

public SoapClient::__call(string $name, array $args): mixed

Calling this method directly is deprecated. Usually, SOAP functions can be called as methods of the SoapClient object; in situations where this is not possible or additional options are needed, use SoapClient::__soapCall().

Bağımsız Değişkenler

name

The name of the SOAP function to call.

args

An array of the arguments to pass to the function. This can be either an ordered or an associative array. Note that most SOAP servers require parameter names to be provided, in which case this must be an associative array.

Dönen Değerler

SOAP functions may return one, or multiple values. If only one value is returned by the SOAP function, the return value will be a scalar. If multiple values are returned, an associative array of named output parameters is returned instead.

On error, if the SoapClient object was constructed with the exceptions option set to false, a SoapFault object will be returned.

add a note

User Contributed Notes 2 notes

up
22
philipp dot gruber at catchoftheday dot com dot au
10 years ago
If you are using a WSDL, the library will strip out anything from your parameters that is not defined in WSDL, without giving you any notice about this.

So if your parameters are not fully matching the WSDL, it will simply send no parameters at all.
This can be a bit hard to debug if you don't have access to the target server.

__soapCall() expects parameters in an array called 'parameters' as opposed to calling the function via it's WSDL name, where it accepts the parameters as a plain array.

I.e. if a function called sendOrder expects a parameter (array) called orderDetails, you can call it like this:

$orderDetails = array(/* your data */);
$soap->sendOrder(array('orderDetails' => $orderDetails));

Which is equivalent to:

$client->__soapCall('sendOrder', array('parameters' => array('orderDetails' => $orderDetails)));

Note the additional 'parameters' key used in __soapCall().
up
7
KRavEN
15 years ago
extend of __call thats adds a retry to handle the occasional 'Could not connect to host' exceptions

<?php
class LocalSoapClient extends SoapClient
{

public function
__call($function_name, $arguments)
{
$result = false;
$max_retries = 5;
$retry_count = 0;

while(!
$result && $retry_count < $max_retries)
{
try
{
$result = parent::__call($function_name, $arguments);
}
catch(
SoapFault $fault)
{
if(
$fault->faultstring != 'Could not connect to host')
{
throw
$fault;
}
}
sleep(1);
$retry_count ++;
}
if(
$retry_count == $max_retries)
{
throw new
SoapFault('Could not connect to host after 5 attempts');
}
return
$result;
}
}
?>
To Top