Zend Framework 2 SOAP服务器WSDL无法加载

时间:2013-04-19 18:24:40

标签: soap wsdl zend-framework2

我无法让SOAP服务器在Zend Framework 2模块中运行。我不完全确定,但我认为问题是WSDL文件。我尝试通过Zend Framework提供的Autodiscover创建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

我为此服务测试添加了一个自己的模块,这是结构,模块称为“服务”:

-Services
--config
---module.config.php
--src
---Services
----API
-----1.0
------servicesAPI.php
---Controller
----ServicesController.php
--view
---services
----serivces
-Module.php
-autoload_classmap.php

这是我的文件“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-LINK / services时,它会给我以下内容:

<?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>

在此调用中,还会写入PHP错误输出! 如果我尝试在浏览器中打开服务?wsdl,它会显示我(chrome和safari):

This page contains the following errors:

error on line 3 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error.

This method takes a value and gives back the md5 hash of the value

但是,如果我检查元素,它看起来完全没问题:

<?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>

我可以使用任何xml验证器验证此xml,它似乎是有效的。

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

  • 根据:https://bugs.php.net/bug.php?id=48216我尝试将wsdl xml保存到文件中并在启动soap服务器时从此文件中打开它,失败
  • 我尝试使用try / catch运行自动发现和soapserver语句来捕获任何异常,没有任何显示
  • 我尝试回显到toXML()和其他输出,失败
  • 使用XMLReader :: open和isValid确保xml有效(确实如此)

更多信息:

  • PHP Version 5.3.23
  • Ubuntu服务器11.04
  • 加载php-soap模块
  • Zend Framework 2.1.4版

任何帮助或提示都表示赞赏。提前谢谢。

1 个答案:

答案 0 :(得分:2)

尝试以这种方式实例化Soap Server类:

...
private function handleSOAP() {
    $soap = new Server(
        null, array(,
            'wsdl' => http-LINK/services?wsdl,
        )
    );
    $soap->setClass('servicesAPI');
    $soap->handle();
}
....

此外,您应该将此行添加到indexAction()

的末尾
return $this->getResponse();

..它会禁用布局。