简体   繁体   中英

Zend_Soap_AutoDiscover doesn't generate wsdl file

I have a problem to generate WSDL file from Zend_Soap_AutoDiscover class.
Could someone explain what I'm doing wrong?

In bootstrap.php I have a method:

public function _initWsdl()
{
    require_once("http://localhost:8080/zf_mta/backend.php");
    $autoDiscover = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');
    $autoDiscover->setClass('Backend');
    $autoDiscover->setUri('http://localhost:8080/zf_mta/backend.php');
    $autoDiscover->handle();

    return $autoDiscover;
}

And here is backend.php class

class Order {

    /** @var string */
    public $productid;
    /** @var string */
    public $customerid;
    /** @var int */
    public $productcnt;

    public function __construct($productid,$customerid,$productcnt) {
        $this->productid  = $productid;
        $this->customerid = $customerid;
        $this->productcnt = $productcnt;
    }
}

class Orders {

    /** @var Order[] */
    public $orders;

}

class Backend {

    /**
     * @param Orders $orders
     * @return string
     */
    public function placeOrders($orders) {
        return print_r($orders,1);
    }


}

I'm getting error:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request...

error_log:

[07-Sep-2012 13:39:48 UTC] PHP Warning:  require_once() [<a href='function.require-once'>function.require-once</a>]: http:// wrapper is disabled in the server configuration by allow_url_include=0 in E:\Zend Server\Apache2\htdocs\zf_mta\application\Bootstrap.php on line 18
[07-Sep-2012 13:39:48 UTC] PHP Warning:  require_once(http://localhost:8080/zf_mta/backend.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: no suitable wrapper could be found in E:\Zend Server\Apache2\htdocs\zf_mta\application\Bootstrap.php on line 18
[07-Sep-2012 13:39:48 UTC] PHP Fatal error:  require_once() [<a href='function.require'>function.require</a>]: Failed opening required 'http://localhost:8080/zf_mta/backend.php' (include_path='E:\Zend Server\Apache2\htdocs\zf_mta\application/../library;E:\Zend Server\Apache2\htdocs\zf_mta\library;.;E:\Zend Server\ZendServer\share\ZendFramework\library') in E:\Zend Server\Apache2\htdocs\zf_mta\application\Bootstrap.php on line 18

Florent's comment solves the first problem: your PHP configuration is prohibiting the inclusion of files using HTTP. So you'll need to change the require statement to refer to the file's name in the file system.

However, I see several other problems with your code:

  • You are setting the URI of the generated WSDL to be the URI of the Backend class. This is not going to work, as that file does not contain the necessary code to act as either a SOAP client or a SOAP server.

  • Zend_Soap_Autodiscover is usually used in a SOAP server to respond to a request from a client for a copy of the WSDL. Therefore, you would normally include that code in a method that is specifically intended to handle that request, not in the application bootstrap.

  • Disregarding the previous point, I also noticed that you are returning the Zend_Soap_Autodiscover instance at the end of the _initWsdl() function. I'm pretty sure the code calling the _init...() methods disregards any values or objects that are passed back from those methods, so ultimately this code will do nothing.

I think you need to check out some sample code to really understand how to implement a SOAP server using Zend Framework. The following snippet is about the simplest example of using Zend Framework for SOAP services that I could come up with: http://pastebin.com/9mb64LeG Note that it doesn't use the Zend MVC or routing infrastructure, but it might help you get your head around the basic usage of Zend_Soap_Server and Zend_Soap_Autodiscover .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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