Magento Soap API works locally but not remotely

I created my own API for Magento Enterprise 1.11. The API call via Soap v1 works fine on local, but I cannot make calls from local to remote.

Using PHP interactive shell on my localdev:

php > $client = new SoapClient(WSDL_URI,array('trace'=>1));
php > $client->login(API_USER,API_KEY);
php > var_dump($client->__getLastResponse());
string(538) "<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:loginResponse><loginReturn xsi:type="xsd:string">f0eec73e49665aaf9cc4a6644fba5dc6</loginReturn></ns1:loginResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

      

I was able to do this successfully from localhost as well as between two local VMs running on my dev machine. I can also access my custom API methods without issue.

However, when I try to make a soap client for my remote test environment, I can create the client, but calling the $ client-> login () method, or any subsequent call, results in the following:

php > $client = new SoapClient(REMOTE_WSDL_URI,array('trace'=>1));
php > $client->login(API_USER,API_KEY);
PHP Warning:  Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://REMOTE_HOST/index.php/api/index/index/wsdl/1/' : failed to load external entity "http://REMOTE_HOST/index.php/api/index/index/wsdl/1/" in php shell code:1
Stack trace:
#0 php shell code(1): SoapClient->__call('login', Array)
#1 php shell code(1): SoapClient->login(API_USER, API_KEY)
#2 {main}
php > var_dump($client->__getLastRequestHeaders());
string(255) "POST /index.php/api/index/index/ HTTP/1.1
Host: REMOTE_HOST
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.3.18-1~dotdeb.0
Content-Type: text/xml; charset=utf-8
SOAPAction: "urn:Mage_Api_Model_Server_HandlerAction"
Content-Length: 550

php > var_dump($client->__getLastResponseHeaders());
string(840) "HTTP/1.1 500 Internal Service Error
Date: Mon, 11 Feb 2013 19:06:56 GMT
Server: Apache/2.2.16 (Debian)
X-Powered-By: PHP/5.3.19-1~dotdeb.0
Set-Cookie: PHPSESSID=7uqrcmiv96hroubnb1uu7c7cm6; expires=Wed, 13-Feb-2013 01:06:56 GMT; path=/; domain=.REMOTE_HOST; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: CUSTOMER=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.REMOTE_HOST; httponly
Set-Cookie: CUSTOMER_INFO=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.REMOTE_HOST; httponly
Set-Cookie: CUSTOMER_AUTH=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=.REMOTE_HOST; httponly
Content-Length: 468
Vary: Accept-Encoding
Connection: close
Content-Type: text/xml; charset=utf-8

php > var_dump($client->__getLastResponse());
string(468) "<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>WSDL</faultcode><faultstring>SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://REMOTE_HOST/index.php/api/index/index/wsdl/1/' : failed to load external entity "http://REMOTE_HOST/index.php/api/index/index/wsdl/1/"
</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>

      

When I find // REMOTE _HOST / index.php / api /? Wsdl I get the standard Magento WSDL.

Both environments have the same 99.99%:

  • Server version: Apache / 2.2.16 (Debian) (both local and remote)
  • PHP 5.3.18 (local dev) 5.3.19 (remote host)
  • Apache / PHP configurations are the same.
  • The code base is identical

I have counted intewebs for clues, including:

I've tried the Content-Length header fix mentioned in the sedond-to-last link and pretty much anything I could think of ... Stumped.

+3


source to share


2 answers


As long as you can download the WSDL ( http://REMOTE_HOST/index.php/api/index/index/wsdl/1/

) url from your computer, your remote server cannot communicate with itself via REMOTE_HOST

.

The PHP SoapServer object (used by the Magento implementation) needs to contact the WSDL to see what methods are exposed.

For reasons that I could never understand, the overall network configuration for the server does not have access to its own DNS records. Connect to your server via SSH and try running the following



curl http://REMOTE_HOST/index.php/api/index/index/wsdl/1/

      

My guess is you will get a network timeout or an unknown error REMOTE_HOST

. Correct the configuration so that your server can access itself and everything should start working.

+13


source


Perhaps you can try changing the host's DNS servers.



vim /etc/resolv.conf to add Google 8.8.8.8, 8.8.4.4

      

0


source







All Articles