在 PHP 中使用 Zend Framework 设置 SOAP Web 服务

发布于 2024-12-17 19:43:18 字数 3599 浏览 2 评论 0原文

我正在尝试使用标准 Zend Framework 项目设置 Web 服务。

错误

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: 
Couldn't load from 'http://localhost/webservice/index' : Extra content at the end 
of the document in 
C:\wamp\www\delegate-events-portal\library\Zend\Soap\Client\Common.php:51 
Stack trace: #0 
C:\wamp\www\delegate-events-portal\library\Zend\Soap\Client\Common.php(51): 
SoapClient->SoapClient('http://localhos...', Array) #1 
C:\wamp\www\delegate-events-portal\library\Zend\Soap\Client.php(1026): 
Zend_Soap_Client_Common->__construct(Array, 'http://localhos...', Array) #2 
C:\wamp\www\delegate-events-portal\library\Zend\Soap\Client.php(1182): 
Zend_Soap_Client->_initSoapClientObject() #3 
C:\wamp\www\delegate-events-portal\library\Zend\Soap\Client.php(1106): 
Zend_Soap_Client->getSoapClient() #4 [internal function]: 
Zend_Soap_Client->__call('getCompanies', Array) #5 
C:\wamp\www\delegate-events-portal\application\controllers
\WebserviceController.php(98): 
Zend_Soap_Client->getCompanies() #6 
C:\wamp\www\delegate-events-portal\application\controllers\WebserviceC in 
C:\wamp\www\delegate-events-portal\library\Zend\Soap\Client\Common.php on line 51

代码

application/controllers/WebserviceController.php

class WebserviceController extends Portal_BaseController
{
    public $resourceId = 'Webservice';
    private $client;

    public function init(){}

    public function indexAction()
    {
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        //Set up the Web Service Manager
        $auto = new Zend_Soap_AutoDiscover();
        $auto->setClass('Webservice_Manager');
        $auto->handle();
    }

    public function clientAction()
    {
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        try
        {
            $this->client = new Zend_Soap_Client('http://localhost/webservice/index');
        }
        catch(SoapFault $s)
        {
            echo '<pre>';
            print_r($s);
            echo '<pre>';
            die('ERROR: [' . $s->faultcode . '] ' . $s->faultstring);
        }
        catch (Exception $e)
        {
            die('ERROR: ' . $e->getMessage());
        }

        print_r($this->client->getCompanies());
    }
}

library/Webservice/Manager.php

class Webservice_Manager
{

    /**
     * Returns all the companies for a particular summit
     * @param int $summitID
     * @return array
     */
    public function getCompanies($summitID = 118)
    {
        $companiesModel = new Application_Model_DbTable_Company();
        return $companiesModel->getCompaniesAndAttendees($summitID, NULL, NULL, true, NULL)->toArray();
    }

    /**
     * Returns all the attendees for a particular summit
     * @param int $summitID
     * @param int $companyID
     * @return array
     */
    public function getAttendees($summitID = 118, $companyID = 3767) 
    {
        $attendeesModel = new Application_Model_DbTable_Attendee();
        return $attendeesModel->getAttendees($summitID, $companyID, false)->toArray();
    }
}

潜在解决方案

我很确定问题是由Zend 中的路由系统。当我获取服务器代码并将其放置在框架之外(在根文件夹中)时,代码工作正常。在这种情况下,我对代码所做的唯一更改是 wsdl 的位置。我使用了绝对路径并需要我需要的任何文件。

考虑到这一点,如何让 Web 服务在我的 Zend 项目内部工作,而不是在外部工作?

任何帮助将不胜感激。我快把头发扯下来了!

I'm trying to set up a Web Service using a standard Zend Framework project.

Error

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: 
Couldn't load from 'http://localhost/webservice/index' : Extra content at the end 
of the document in 
C:\wamp\www\delegate-events-portal\library\Zend\Soap\Client\Common.php:51 
Stack trace: #0 
C:\wamp\www\delegate-events-portal\library\Zend\Soap\Client\Common.php(51): 
SoapClient->SoapClient('http://localhos...', Array) #1 
C:\wamp\www\delegate-events-portal\library\Zend\Soap\Client.php(1026): 
Zend_Soap_Client_Common->__construct(Array, 'http://localhos...', Array) #2 
C:\wamp\www\delegate-events-portal\library\Zend\Soap\Client.php(1182): 
Zend_Soap_Client->_initSoapClientObject() #3 
C:\wamp\www\delegate-events-portal\library\Zend\Soap\Client.php(1106): 
Zend_Soap_Client->getSoapClient() #4 [internal function]: 
Zend_Soap_Client->__call('getCompanies', Array) #5 
C:\wamp\www\delegate-events-portal\application\controllers
\WebserviceController.php(98): 
Zend_Soap_Client->getCompanies() #6 
C:\wamp\www\delegate-events-portal\application\controllers\WebserviceC in 
C:\wamp\www\delegate-events-portal\library\Zend\Soap\Client\Common.php on line 51

Code

application/controllers/WebserviceController.php

class WebserviceController extends Portal_BaseController
{
    public $resourceId = 'Webservice';
    private $client;

    public function init(){}

    public function indexAction()
    {
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        //Set up the Web Service Manager
        $auto = new Zend_Soap_AutoDiscover();
        $auto->setClass('Webservice_Manager');
        $auto->handle();
    }

    public function clientAction()
    {
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        try
        {
            $this->client = new Zend_Soap_Client('http://localhost/webservice/index');
        }
        catch(SoapFault $s)
        {
            echo '<pre>';
            print_r($s);
            echo '<pre>';
            die('ERROR: [' . $s->faultcode . '] ' . $s->faultstring);
        }
        catch (Exception $e)
        {
            die('ERROR: ' . $e->getMessage());
        }

        print_r($this->client->getCompanies());
    }
}

library/Webservice/Manager.php

class Webservice_Manager
{

    /**
     * Returns all the companies for a particular summit
     * @param int $summitID
     * @return array
     */
    public function getCompanies($summitID = 118)
    {
        $companiesModel = new Application_Model_DbTable_Company();
        return $companiesModel->getCompaniesAndAttendees($summitID, NULL, NULL, true, NULL)->toArray();
    }

    /**
     * Returns all the attendees for a particular summit
     * @param int $summitID
     * @param int $companyID
     * @return array
     */
    public function getAttendees($summitID = 118, $companyID = 3767) 
    {
        $attendeesModel = new Application_Model_DbTable_Attendee();
        return $attendeesModel->getAttendees($summitID, $companyID, false)->toArray();
    }
}

Potential Solution

I'm pretty sure the issue is caused by the routing system in Zend. When I take the server code and place it outside of the framework (in the root folder), the code works fine. The only changes I made to the code in this scenario was the location of the wsdl. I used an absolute path and required any of the files I needed.

With this in mind, how do I get the web service to work from within my Zend Project and not when it's outside?

Any help would be much appreciated. I'm tearing my hair out!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

掐死时间 2024-12-24 19:43:19

尝试更改您的 indexAction 以使用 Zend_Soap_Server。它不是自动发现,但可以完成工作。

public function indexAction()
{
    $this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender(true);

    //Set up the Web Service Manager
    $auto = new Zend_Soap_Server(null, array(
        'uri' => 'http://localhost/webservice/index'
    ));
    $auto->setClass('Webservice_Manager');
    $auto->handle();
}

Try changing your indexAction to use Zend_Soap_Server. It's not AutoDiscover but gets the job done.

public function indexAction()
{
    $this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender(true);

    //Set up the Web Service Manager
    $auto = new Zend_Soap_Server(null, array(
        'uri' => 'http://localhost/webservice/index'
    ));
    $auto->setClass('Webservice_Manager');
    $auto->handle();
}
哥,最终变帅啦 2024-12-24 19:43:19
public function webserviceAction(){
     $this->_helper->layout->disableLayout();`enter code here`       
    $this->_helper->viewRenderer->setNoRender(true);
    //Set up the Web Service
        $auto = new Zend_Soap_Server(null, array(
        'uri' => 'http://localhost/webservice/webservice'
    ));
        $auto->setClass('Webservice_Manager');
        $auto->handle();
}
public function webserviceAction(){
     $this->_helper->layout->disableLayout();`enter code here`       
    $this->_helper->viewRenderer->setNoRender(true);
    //Set up the Web Service
        $auto = new Zend_Soap_Server(null, array(
        'uri' => 'http://localhost/webservice/webservice'
    ));
        $auto->setClass('Webservice_Manager');
        $auto->handle();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文