我正在尝试使用标准的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
代码
应用/控制器/ 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());
}
}
库/ web服务/ 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的位置。我使用了绝对路径并需要我需要的任何文件。
考虑到这一点,我如何让我的Zend项目中的Web服务工作,而不是在外面?
非常感谢任何帮助。我正在撕扯我的头发!
答案 0 :(得分:0)
尝试将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();
}
答案 1 :(得分:0)
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();
}