在 PHP 中使用 Zend Framework 设置 SOAP Web 服务
我正在尝试使用标准 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试更改您的
indexAction
以使用Zend_Soap_Server
。它不是自动发现,但可以完成工作。Try changing your
indexAction
to useZend_Soap_Server
. It's not AutoDiscover but gets the job done.