Magento Soap API在本地工作但不是远程工作

时间:2013-02-11 23:26:37

标签: magento soap wsdl

我为Magento Enterprise 1.11创建了一个自定义API。通过Soap v1调用API在我的本地开发环境中运行良好,但是我无法从本地环境调用远程环境。

在我的localdev上使用PHP交互式shell:

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>

我已经能够从localhost成功完成此操作,以及在我的开发机器上运行的两个本地VM之间。我也可以毫无问题地访问自定义API的方法。

但是,当我尝试将肥皂客户端设置为远程测试环境时,我可以创建客户端,但是对$ client-&gt; login()或任何后续调用的调用会产生以下结果:< / p>

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>

当我点击//REMOTE_HOST/index.php/api/?wsdl时,我得到了标准的Magento WSDL。

两种环境的相同性为99.99%:

  • 服务器版本:Apache / 2.2.16(Debian)(本地开发和远程)
  • PHP 5.3.18(本地开发)5.3.19(远程主机)
  • Apache / PHP配置相同。
  • 代码库相同

我已经在网上搜寻线索,包括:

我尝试过在sedond-to-last链接中提到的“内容长度”标题修复,以及我能想到的其他所有内容......难倒......

2 个答案:

答案 0 :(得分:13)

虽然您可以从计算机加载WSDL URL(http://REMOTE_HOST/index.php/api/index/index/wsdl/1/),但您的远程服务器无法通过其REMOTE_HOST与自己联系。

PHP的SoapServer对象(由Magento的实现使用)需要联系WSDL以了解暴露的方法。

由于我从未弄清楚的原因,这是服务器无法访问自己的DNS条目的常见网络配置。通过SSH连接到您的服务器并尝试运行以下

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

我的猜测是你会收到网络超时或REMOTE_HOST未知错误。修复您的配置,以便服务器可以自行访问,一切都应该开始工作。

答案 1 :(得分:0)

您可以尝试更改主机DNS名称服务器。

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