Zend Framework 2 SOAP server WSDL failed to load

空扰寡人 提交于 2019-12-08 03:49:00

问题


I can't get the SOAP server working in Zend Framework 2 module. I am not completely sure, but I believe that the problem is the WSDL file. I try to create the WSDL file via Autodiscover, which is provided by the Zend Framework. Here is the 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

I added an own module for this services test, this is the structure, module is called "Services":

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

This is my file "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);
    }

}

And this is 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();
    }

}

So when I deploy this and open http-LINK/services in the browser, it gives me the following:

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

On this call also the PHP error output is written! If I try to open the services?wsdl in browser, it shows me this (chrome and 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

But if I inspect the element, it looks completely ok:

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

I can validate this xml with any xml validator, it seems to be valid.

I read all the posts concerning this on stackoverflow, searched google, but none of the solutions helped me. Here a short list of what else I tried:

  • According to this: https://bugs.php.net/bug.php?id=48216 I tried to save the wsdl xml to a file and open it from this file when starting the soap server, fail
  • I tried to run the autodiscover and soapserver statements with try/catch to catch any exceptions, nothing appears
  • I tried with echo-ing through toXML() and other outputs, fail
  • Used XMLReader::open and isValid to make sure, that the xml is valid (it is)

Some more information:

  • PHP Version 5.3.23
  • Ubuntu server 11.04
  • php-soap module is loaded
  • Zend Framework version 2.1.4

Any help or hints are appreciated. Thanks in advance.


回答1:


Try instantiate the Soap Server class this way:

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

Also you should add this line to the end of your indexAction()

return $this->getResponse();

.. it disables the layout.



来源:https://stackoverflow.com/questions/16111209/zend-framework-2-soap-server-wsdl-failed-to-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!