1

我无法让 SOAP 服务器在 Zend Framework 2 模块中工作。我不完全确定,但我相信问题出在 WSDL 文件上。我尝试通过 Zend Framework 提供的 Autodiscover 创建 WSDL 文件。这是错误日志:

[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 错误输出!如果我尝试在浏览器中打开 services?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 保存到一个文件中,并在启动肥皂服务器时从该文件中打开它,失败
  • 我尝试使用 try/catch 运行 autodiscover 和 soapserver 语句来捕获任何异常,没有出现
  • 我尝试通过 toXML() 和其他输出回显,失败
  • 使用 XMLReader::open 和 isValid 来确保 xml 是有效的(它是)

更多信息:

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

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

4

1 回答 1

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();

..它禁用布局。

于 2013-06-18T13:37:54.357 回答