我正在嘗試使用標準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