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

Aus*_*gen 3 soap wsdl magento

我为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>
Run Code Online (Sandbox Code Playgroud)

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

但是,当我尝试在我的远程测试环境中创建一个soap客户端时,我能够创建客户端,但是对$ client-> login()或任何后续调用的调用会产生以下结果:

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>
Run Code Online (Sandbox Code Playgroud)

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

这两个环境的相同性为99.99%:

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

我已经搜索了intewebs的线索,包括:

我已经尝试过在sedond-to-last链接中提到的"Content-Length"标题修复,以及我能想到的其他所有内容......难倒.

Ala*_*orm 13

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

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

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

curl http://REMOTE_HOST/index.php/api/index/index/wsdl/1/
Run Code Online (Sandbox Code Playgroud)

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