Question

I'm experiencing a problem with my SOAP solution. Sometimes I get an error saying the following:

Function (functionA) is not a valid method for this service

Edit 8 months later Although I could not find the cause of the problem I was able to work around it. Whenever I recieve an response from the API I check for the SoapFault and just send another identical request and use the answer that comes back the second time.(posted as an answer)

This occurs in calls from PHP like:

functionA() - expected response
functionA() - expected response
functionA() - SoapFault
functionA() - expected response

Same result is to be expected in all the above calls and the same parameters are used(if any). Since it's working fine for almost all calls I know that the function and the corresponding WSDL is there.

What I thougt were the problem was caching an old version which would not have that function. I tried disabling the caching with:

ini_set("soap.wsdl_cache_enabled", "0");

And makeing every call with added with a random dummy parameter as well as disabling it when I use Zend_SoapClient.

'cache_wsdl' = false

I hope someone could point me in any direction or have any direct suggestion on what could be the cause.

My code looks like:

public function __construct()
{
        $wsdl =  "http://catlovers.nl/index.php?wsdl&dummy=".rand(1000,9999);

        $this->_client = new Zend_Soap_Client($wsdl, array(
            'soapVersion' => SOAP_1_1,
            'cache_wsdl' => false 

        ));
        $this->_client->setWsdlCache(false);
}

function __call($name, $arguments) // Calls are made this way
{
    array_unshift($arguments, $this->_apiKey, $this->_user, $this->_password);
    return call_user_func_array(array($this->_client, $name), $arguments);
}
public function getCat()
{
    return ($this->__call('getCat',array()));
}

On "the other side" I have:

$server = new nusoap_server();

$server->wsdl->addComplexType('Cat', ....

$server->register( 'getCat', return Cat ...

function getCat($apikey, $email, $password)
{
  $cat = $db->get("redCat");
  return $cat;
}
Was it helpful?

Solution 3

So the problem was still there after trying other solutions so I was never able to find underlying cause of the problem. On the other hand I found a way to work around the problem that has been working since I wrote it. This is how my call to the API looks like with user,password and key for authentication.

function __call($name, $arguments)
{
    /* Using the stored data to ensure that the user is allowed to access */
    /* ............... */

    array_unshift($arguments, $this->_apiKey, $this->_user, $this->_password);
    $call = call_user_func_array(array($this->_client, $name), $arguments);
    if(isset($call->faultstring) && substr(trim($call->faultstring),0,7) == "Function")
    {
        $recall = call_user_func_array(array($this->_client, $name), $arguments);
        return $recall;
    }
    else
        return $call;
}

This is basicly: if it doesn't work the first time just try again.

OTHER TIPS

First of all, try to call function using built-in SoapClient class and printing debug information:

$wsdl =  "http://abcd.com/index.php?wsdl&dummy=".rand(1000,9999);
$soap = new SoapClient($wsdl, array(
   'cache_wsdl' => WSDL_CACHE_NONE,
   'trace' => true,
));

try {
    var_dump($soap->functionA());
} catch ( Exception $ex ) {
    var_dump($ex);
}
var_dump($soap->__getLastRequest());
var_dump($soap->__getLastRequestHeaders());
var_dump($soap->__getLastResponse());
var_dump($soap->__getLastResponseHeaders());

This way you'll know where is the problem. If everything is ok all the time, the problem is in Zend's class. If not, look what service responds. May be there is some server-side error or dummy generation with such id fails

I guess your problem is related to nusoap, because for many years I'm using PHP soap server/client and I never faced this problem. (but I always had strange problems with nusoap lib)

currently I'm using jool.nl web service helper which is very powerfull yet neat and object oriented library not only makes coding easier and cleaner but also provides you object oriented approach to web service designing. It also provides a nice web interface for your web service with documentation.

As this library uses internal PHP SOAP server I'm pretty sure you're problem will be disappear then.

I suggest you to give it a try and I'm sure if you make your first web service with this library you will never try something else.

I hope this helps you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top