我正在尝试使用标准Zend Framework项目来设置Web服务。使用Zend框架在PHP中设置SOAP webservice
错误
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服务,而不是在外部工作?
任何帮助将不胜感激。我正在把我的头发撕掉!
任何想法的家伙? – user1065700
你为什么要扩展'Portal_BaseController'?它是否扩展了'Zend_Controller_Action'? 此外,这个应用程序的目的是为服务器或客户端?我问的原因是因为我认为你正在编写一个服务器应用程序,但我没有看到任何代码来实例化一个Zend_Soap_Server对象。 – JamesG