我使用ZF实现了一个Web服务(教程:http://benjaminprevot.fr/2010/06/16/produire-un-webservice-soap-avec-zend-framework/ [法语])
原始教程工作正常,
但我不知道为什么当我在服务器端调用getDetections()时,框架会引发异常。
class WsController extends BaseController
{
public function detectionsAction()
{
if (is_null($this->getRequest()->getParam('wsdl'))) {
// Traitement de la requête
$server = new Zend_Soap_Server('http://localhost/my_app_site/public/ws/detections/?wsdl');
$server->setClass('Application_Model_WsDetection');
$server->handle();
} else {
// Retour de la WSDL
$wsdl = new Zend_Soap_AutoDiscover();
$wsdl->setClass('Application_Model_WsDetection');
$wsdl->handle();
}
exit;
}
}
class Application_Model_WsDetection
{
/**
* Retourne la liste des détections enregistrées.
*
* @return integer
*/
public function getDetections()
{
// **the folowing two lines raise an error**
$detectionsModel = new Application_Model_Detection; //*
$detectionsModel->fetchAll(); //*
return 2 ; // just for test
}
}
class WsClientController extends BaseController
{
public function detectionsAction()
{
$client = new Zend_Soap_Client('http://localhost/my_app_site/public/ws/detections/?wsdl');
$result = $client->getDetections(); // **This is the line 28**
Zend_Debug::dump($result);
}
}
http://localhost/my_app_site/public/wsclient/detections/?wsdl
Fatal error:
Uncaught SoapFault exception: [Receiver] Unknown error in C:\xampp\ZendFramework\library\Zend\Soap\Client.php:1121
Stack trace:
#0 C:\xampp\ZendFramework\library\Zend\Soap\Client.php(1121): SoapClient->__soapCall('getDetections', Array, NULL, NULL, Array)
#1 C:\xampp\htdocs\my_app_site\application\controllers\WsClientController.php(28): Zend_Soap_Client->__call('getDetections', Array)
#2 C:\xampp\htdocs\my_app_site\application\controllers\WsClientController.php(28): Zend_Soap_Client->getDetections()
#3 C:\xampp\ZendFramework\library\Zend\Controller\Action.php(513): WsClientController->detectionsAction()
#4 C:\xampp\ZendFramework\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('detectionsActio...')
#5 C:\xampp\ZendFramework\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#6 C:\xampp\ZendFramework\library\Zend\Appl in C:\xampp\ZendFramework\library\Zend\Soap\Client.php on line 1121
我希望我能很好地解释我的问题
非常感谢。
(对不起我的英语不好)
答案 0 :(得分:0)
您是否能够在Application_Model_Detection
之外的任何地方实例化getDetections()
个对象?
如果是,那么问题可能是Zend的自动加载器在核心SoapClient::__soapCall()
方法中无法正常工作。 (或者在其中发生的call_user_func()
内。)您可以通过添加
require_once("{full path to Application_Model_Detection file}");
无论如何,我怀疑这是一个自动加载器命名空间问题。你的'Application_'前缀对Zend有特殊意义,所以要确保该类能够被实例化。