Zend SOAP 服务器 SOAP 错误:解析 WSDL:无法从“X”加载:无法加载外部实体“X”


Zend SOAP Server SOAP-ERROR:Parsing WSDL: Couldn't load from 'X' : failed to load external entity 'X"

<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://testws.localhost/album/wsdl' : failed to load external entity "http://testws.localhost/album/wsdl"
            </faultstring>
        </SOAP-ENV:Fault>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我正在尝试使用 Zend Framework 2.2.1 在 php 中创建一个简单的测试 Web 服务。我正在使用 XAMPP v1.8.2-0。安装的 php 版本是 5.4.16。我一直遵循了 http://framework.zend.com/manual/2.0/en/user-guide/skeleton-application.html 的骨架应用程序教程,直到我有一个正常运行的控制器。

wsdl 路径是 testws.localhost/album/

wsdl 或 testws.localhost/album?wsdl该服务位于testws.localhost/album。127.0.0.1 代替 testws.localhost 没有区别。

访问 WSDL url 会返回一个看似有效的 WSDL 文件,XMLSpy 会加载/验证它。在浏览器中访问该服务会导致上述错误响应,该响应没有提供有关为什么它无法加载 WSDL 的任何详细信息。

将生成的 WSDL 输出保存到文件并使用该文件的路径,以及在 soap 请求方法中将其生成为 php 中的文本都会产生相同的错误,无法从"X"加载:无法加载外部实体"X"。可以从 WSDL 文件在应用程序目录中的位置读取并回显出来。

花了好几天的时间试图解决这个问题,并在这里和网络上查看了很多类似的问题,但所有这些问题要么神奇地自行解决,要么没有公认的答案,没有任何建议对我有用。代码包含在下面,如果需要任何其他信息,请告诉我,我对zend框架/php/xampp相对缺乏经验,这让我完全停止了。

专辑控制器.php

<?php
namespace Album'Controller;
require_once 'Soaptest.php';
use Zend'Mvc'Controller'AbstractActionController;
use Zend'View'Model'ViewModel;
use Zend'Soap'Server;
use Zend'Soap'AutoDiscover;
class AlbumController extends AbstractActionController
{
    private $_WSDL_URI = "http://testws.localhost/album/wsdl";
    private $_URI = "http://testws.localhost/album";
    public function indexAction()
    {    
        if(isset($_GET['wsdl'])) 
        {
            $this->handleWSDL();
        } 
        else 
        {
            $this->handleSOAP();
        }
        return $this->getResponse();
    }
    public function wsdlAction()
    {   
        $this->handleWSDL();
        return $this->getResponse();
    }
    private function handleWSDL() {
        $autodiscover = new AutoDiscover();
        $autodiscover->setUri('Soaptest');
        $autodiscover->setClass($this->_URI);
        $autodiscover->handle();
    }
    private function handleSOAP() {
        try 
        {
            $server = new Server($this->_WSDL_URI);
            $server->setClass('Soaptest');
            $server->handle();          
        } 
        catch (Exception $E) 
        {  
            $E->faultstring->dump("error.wsdl"); 
        }  
    }
}

肥皂测试.php

<?php
class Soaptest {
    /**
     * This method returns a string
     * 
     * @param String $value
     * @return String
     */
    public function hello($value) {
        return "hi";
    }
}

在 httpd-vhosts.conf 中

<VirtualHost testws.localhost:80>
    DocumentRoot "C:/xampp/htdocs/ws/ZendApp/public"
    ServerName testws.localhost
    ServerAlias www.testws.localhost
    SetEnv APPLICATION_ENV "development"
    <Directory "C:/xampp/htdocs/ws/ZendApp/public">
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

主机文件

127.0.0.1           testws.localhost localhost

WSDL XML

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://testws.localhost/album" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" name="Soaptest" targetNamespace="http://testws.localhost/album">
    <types>
        <xsd:schema targetNamespace="http://testws.localhost/album"/>
    </types>
    <portType name="SoaptestPort">
        <operation name="hello">
            <documentation>This method returns a string</documentation>
            <input message="tns:helloIn"/>
            <output message="tns:helloOut"/>
        </operation>
    </portType>
    <binding name="SoaptestBinding" type="tns:SoaptestPort">
        <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="hello">
            <soap:operation soapAction="http://testws.localhost/album#hello"/>
            <input>
                <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://testws.localhost/album"/>
            </input>
            <output>
                <soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://testws.localhost/album"/>
            </output>
        </operation>
    </binding>
    <service name="SoaptestService">
        <port name="SoaptestPort" binding="tns:SoaptestBinding">
            <soap:address location="http://testws.localhost/album"/>
        </port>
    </service>
    <message name="helloIn">
        <part name="value" type="xsd:string"/>
    </message>
    <message name="helloOut">
        <part name="return" type="xsd:string"/>
    </message>
</definitions>

我认为问题出在您的控制器上,首先您的$_URI必须是

$_URI = "http://testws.localhost/album";

(即使用 http 架构(。

其次你传递了错误的参数给AutoDiscoverAutoDiscover的第一个参数不是 url,尝试用这个替换你的handleWSDL方法:

private function handleWSDL() {
    $autodiscover = new AutoDiscover();
    $autodiscover->setClass('Soaptest')
                 ->setUri($this->_URI);
    $autodiscover->handle();
}

我在Zend + Php上收到此错误

SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://wsdl...' : failed to load external entity "http://wsdl..."

我发现问题是由服务器无法访问 URL 引起的。这很有趣,但它发生在托管 Web 服务的服务器无法卷曲/获取/读取它自己的 wsdl url 的地方。

尝试 cURL wsdl URL,看看是否可以取回一些东西?

看起来实际上根本没有真正的问题。我正在创建的 c# 示例应用程序和 XMLSpy 都能够读取 wsdl 文件并向服务发出请求。

我猜测生成的错误是由于我的 Web 浏览器没有发送 soap 请求,并且为了处理 wsdl 文件,SOAP 服务器尝试将请求中的信息与服务描述进行匹配。我本来希望出现一个关于缺少有效 soap 请求的错误,而不是关于完全有效且可用的 wsdl 文件的错误。不确定此错误是由 zend soap 服务器还是它使用的底层 php soap 服务器创建的。

因此,如果其他人看到此错误,请确保您使用的是适当的 SOAP 客户端进行测试。