Zend Framework 2 SOAP服务器WSDL加载失败

Zend Framework 2 SOAP服务器WSDL加载失败,soap,wsdl,zend-framework2,Soap,Wsdl,Zend Framework2,我无法使SOAP服务器在Zend Framework 2模块中工作。我不完全确定,但我相信问题在于WSDL文件。我尝试通过Zend框架提供的自动发现创建WSDL文件。以下是error.log: [Fri Apr 19 20:39:29 2013] [error] [client 172.23.31.109] PHP Warning: SoapServer::SoapServer(): I/O warning : failed to load external entity "http-LINK

我无法使SOAP服务器在Zend Framework 2模块中工作。我不完全确定,但我相信问题在于WSDL文件。我尝试通过Zend框架提供的自动发现创建WSDL文件。以下是error.log:

[Fri Apr 19 20:39:29 2013] [error] [client 172.23.31.109] PHP Warning:  SoapServer::SoapServer(): I/O warning : failed to load external entity "http-LINK/services?wsdl" in /PATH/public_html/vendor/zendframework/zendframework/library/Zend/Soap/Server.php on line 749
[Fri Apr 19 20:39:29 2013] [error] [client 172.23.31.109] PHP Fatal error:  SOAP-ERROR: Parsing WSDL: Couldn't load from 'http-LINK/services?wsdl' : failed to load external entity "http-LINK/services?wsdl"\n in /PATH/public_html/vendor/zendframework/zendframework/library/Zend/Soap/Server.php on line 749
我为这个服务测试添加了自己的模块,这是结构,模块称为“服务”:

这是我的文件“servicesAPI.php”
class servicesAPI {
    /**
     * This method takes a value and gives back the md5 hash of the value
     * 
     * @param String $value
     * @return String
     */
    public function md5Value($value) {
        return md5($value);
    }

}
这是ServicesController.php:
namespace Services\Controller;

ini_set("soap.wsdl_cache_enabled", 0);

use Zend\Mvc\Controller\AbstractActionController;
use Zend\Soap\AutoDiscover;
use Zend\Soap\Server;

require_once __DIR__ . '/../API/1.0/servicesAPI.php';

class ServicesController extends AbstractActionController {

    private $_options;
    private $_URI = "http-LINK/services";
    private $_WSDL_URI = "http-LINK/services?wsdl";

    public function indexAction() {
        if (isset($_GET['wsdl'])) {
            $this->handleWSDL();
        } else {
            $this->handleSOAP();
        }
    }

    private function handleWSDL() {

        $autodiscover = new AutoDiscover();
        $autodiscover->setClass('servicesAPI')
                ->setUri($this->_URI);
        $autodiscover->handle();
    }

    private function handleSOAP() {

        $soap = new Server($this->_WSDL_URI);
        $soap->setClass('servicesAPI');
        $soap->handle();
    }

}
因此,当我部署此功能并在浏览器中打开http链接/服务时,它会提供以下信息:

<?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-LINK/services?wsdl' : failed to load external entity "http-LINK/services?wsdl"
</faultstring>
                        <detail/>
                </SOAP-ENV:Fault>
        </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
但如果我检查元件,它看起来完全正常:

<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http-LINK/services" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="servicesAPI" targetNamespace="http-LINK/services"><types><xsd:schema targetNamespace="http-LINK/services"/></types><portType name="servicesAPIPort"><operation name="md5Value"><documentation>This method takes a value and gives back the md5 hash of the value</documentation><input message="tns:md5ValueIn"/><output message="tns:md5ValueOut"/></operation></portType><binding name="servicesAPIBinding" type="tns:servicesAPIPort"><soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/><operation name="md5Value"><soap:operation soapAction="http-LINK/services#md5Value"/><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http-LINK/services"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http-LINK/services"/></output></operation></binding><service name="servicesAPIService"><port name="servicesAPIPort" binding="tns:servicesAPIBinding"><soap:address location="http-LINK/services"/></port></service><message name="md5ValueIn"><part name="value" type="xsd:string"/></message><message name="md5ValueOut"><part name="return" type="xsd:string"/></message></definitions>

此方法获取一个值并返回该值的md5散列
我可以用任何xml验证器验证这个xml,它似乎是有效的

我在stackoverflow上阅读了所有与此相关的帖子,搜索了谷歌,但没有一个解决方案对我有帮助。下面是我尝试过的其他方法的简短列表:

  • 根据这一点:我试图将wsdl xml保存到一个文件中,并在启动soap服务器时从该文件打开它,但失败了
  • 我尝试使用try/catch运行autodiscover和soapserver语句来捕获任何异常,但没有显示任何异常
  • 我尝试通过toXML()和其他输出进行echo调用,但失败
  • 使用XMLReader::open和isValid来确保xml是有效的(它是)
更多信息:

  • PHP版本5.3.23
  • Ubuntu服务器11.04
  • php soap模块已加载
  • Zend框架版本2.1.4

任何帮助或提示都将不胜感激。提前感谢。

尝试以下方式实例化Soap服务器类:

...
private function handleSOAP() {
    $soap = new Server(
        null, array(,
            'wsdl' => http-LINK/services?wsdl,
        )
    );
    $soap->setClass('servicesAPI');
    $soap->handle();
}
....
您还应该将这一行添加到indexAction()的末尾


。。它会禁用布局。

http链接是您的虚拟主机吗?是的,http链接是我的开发服务器上的真实URL。我不得不到处更换它,因为以我目前的声誉,我只能发布2个链接。您可以看到如下http链接:那么http链接/服务真的是问题的根源吗?我有一个非常相似的,非常感谢你的回答!我有很长一段时间没有注意到这个问题,所以今天我再次尝试,没有做任何改变——结果成功了。可能是因为我们最近将服务器的PHP版本更新为5.4。我投票支持你禁用布局的答案,谢谢你的提示。
<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http-LINK/services" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="servicesAPI" targetNamespace="http-LINK/services"><types><xsd:schema targetNamespace="http-LINK/services"/></types><portType name="servicesAPIPort"><operation name="md5Value"><documentation>This method takes a value and gives back the md5 hash of the value</documentation><input message="tns:md5ValueIn"/><output message="tns:md5ValueOut"/></operation></portType><binding name="servicesAPIBinding" type="tns:servicesAPIPort"><soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/><operation name="md5Value"><soap:operation soapAction="http-LINK/services#md5Value"/><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http-LINK/services"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http-LINK/services"/></output></operation></binding><service name="servicesAPIService"><port name="servicesAPIPort" binding="tns:servicesAPIBinding"><soap:address location="http-LINK/services"/></port></service><message name="md5ValueIn"><part name="value" type="xsd:string"/></message><message name="md5ValueOut"><part name="return" type="xsd:string"/></message></definitions>
...
private function handleSOAP() {
    $soap = new Server(
        null, array(,
            'wsdl' => http-LINK/services?wsdl,
        )
    );
    $soap->setClass('servicesAPI');
    $soap->handle();
}
....
return $this->getResponse();