SoapClient::__call

(PHP 5, PHP 7, PHP 8)

SoapClient::__callLlamada a una función SOAP (obsoleta)

Descripción

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

La llamada directa a este método es obsoleta. Normalmente, las funciones SOAP pueden ser llamadas como métodos del objeto SoapClient; en los casos donde esto no es posible, o bien es necesario pasar más opciones, utilícese el método SoapClient::__soapCall().

Parámetros

name

El nombre de la función SOAP a llamar.

args

Un array de argumentos a pasar a la función. Esto puede ser un array ordenado o un array asociativo. Tenga en cuenta que la mayoría de servidores SOAP exigen que los nombres de los parámetros sean proporcionados, en cuyo caso debe ser un array asociativo.

Valores devueltos

Las funciones SOAP pueden devolver uno o varios valores. Si solo un valor es devuelto por la función SOAP, el valor de retorno será un escalar. Si varios valores son devueltos, se devuelve un array asociativo de parámetros de salida nombrados en su lugar.

En caso de error, si el objeto SoapClient ha sido construido con la opción exceptions definida como false, se devolverá un objeto SoapFault.

add a note

User Contributed Notes 2 notes

up
21
philipp dot gruber at catchoftheday dot com dot au
11 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
8
KRavEN
16 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