Reputation: 466
I have a cron job that runs every hour to retrieve products that get added to my Magento shop.
Annoyingly it has stopped working and it is proving difficult to de-bug.
When it attempts to run I get the following error:
[SoapFault]
looks like we got no XML document
After doing some research, it looks like the xml being retured could contain errors and therefore not be valid hence the error.
Is there a way to see the retured xml?
The code has not changed, which makes me suspect it may be a setting in magento that has been changed by another user.
The cron job is built on a Symfony 2 platform.
Heres my code:
private $client;
private $session;
private $api = 'https://www.mywebsite.co.uk/api/?wsdl';
private $user = 'xxx';
private $pass = 'xxx';
$output->writeln('Updating shop product...');
$this->client = new \SoapClient($this->api);
$this->session = $this->client->login($this->user, $this->pass);
$products = $this->client->call($this->session, 'catalog_product.list');
Upvotes: 0
Views: 1037
Reputation: 466
Extending the soap client class enabled me to see exactly what was being returned.
class SoapClientNG extends \SoapClient{
public function __doRequest($req, $location, $action, $version = SOAP_1_1, $one_way = 0){
$xml = explode("\r\n", parent::__doRequest($req, $location, $action, $version));
$response = preg_replace( '/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\xFE\xFF|\xFF\xFE|\xEF\xBB\xBF)/', "", $xml[5] );
return $response;
}
}
Turns out the xml it was receiving contained errors. Deleting the products in Magneto and re-entering them fixed the problem.
Upvotes: 1
Reputation: 52493
use a debugging proxy like Fiddler ( Windows ) or Charles ( cross-platform ) to debug/monitor the outgoing request and incoming response.
If the proxy is running let's say on 127.0.0.1:8080
you can tell the soap client to use the proxy via the options array:
private $options = array(
'proxy_host' => '127.0.0.1',
'proxy_port' => '8080',
'cache_wsdl' => WSDL_CACHE_NONE, // try disabling the wsdl cache for debugging
'soap_version' => SOAP_1_1, // check the soap version
'user_agent' => 'Batman incoming v2.0',
// ... more options
);
$this->client = new \SoapClient($this->api, $this->options);
Now the SOAPClient will send the requests through the proxy and you can see the incoming/outgoing xml ( or non-xml , hehe ).
Upvotes: 1