Seemingly random SoapFault: invalid method

I have a problem with my SOAP solution. Sometimes I get the error:

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

      

Edit 8 months later Although I couldn't find the cause of the problem, I was able to work around it. Whenever I get a response from the API, I check the SoapFault and just send another identical request and use the response that is returned a second time (sent as a response)

This happens in PHP calls:

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

      

The same result should be expected in all of the above calls and use the same parameters (if any). Since it works fine for almost all calls, I know the function and the corresponding WSDL are there.

What I chose was caching the old version, which would not have this feature. I tried to disable caching with:

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

      

And make each call add an arbitrary dummy file parameter and also disable it when I use Zend_SoapClient.

'cache_wsdl' = false

      

I hope someone can point me in any direction or give any direct suggestion as to what the cause might be.

My code looks like this:

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;
}

      

+3


source to share


3 answers


So the problem was still resolved after using other solutions, so I could never find the root cause of the problem. On the other hand, I found a way around the problem that has been working since I wrote it. This is how my API call looks like 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 basically: if it doesn't work the first time, try again.

0


source


First of all, try calling the function using the built-in class SoapClient

and printing out the 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 will find out what the problem is. If everything is ok all the time, the problem is in the Zend class. If not, see what the service is responsible for. Maybe there is some error on the server side or creating a dummy type with such ID failure

+3


source


I think your problem is with nusoap because I have been using PHP soap server / client for many years and I have never encountered this problem. (but I've always had weird problems with the nusoap lib)

I am currently using the jool.nl web service helper , which is a very powerful yet neat and object oriented library that not only makes coding easier and cleaner but also provides an object oriented approach to designing web services. It also provides a nice web interface for your web service with documentation.

Since this library uses PHP internal SOAP server I'm sure you are the problem then it will go away.

I suggest you give it a try, and I'm sure if you make your first webservice in this library, you will never try anything else.

Hope this helps you.

+1


source







All Articles