繁体   English   中英

Zend SOAP服务器SOAP-ERROR:解析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 framework / php / xampp相对缺乏经验,这让我彻底停止了。

AlbumController.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"); 
        }  
    }
}

Soaptest.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架构)。

第二要传递了错误的参数来AutoDiscover ,该的第一个参数AutoDiscover不是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服务的服务器无法卷曲/ wget /读取它自己的wsdl url的地方。

尝试cURL wsdl URL,看看你是否能得到回报?

看来,有实际上不是一个真正的问题都没有。 我正在创建的ac#sample app和XMLSpy都能够读取wsdl文件并向服务发出请求。

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

因此,如果其他人看到此错误,请确保使用正确的soap客户端进行测试。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM