我已经使用 ZF 实现了一个网络服务(教程:http ://benjaminprevot.fr/2010/06/16/produire-un-webservice-soap-avec-zend-framework/ [法语])
原始教程工作正常,
但我不知道为什么当我在服务器端调用 getDetections() 时,框架会引发异常。
代码:
1.1。服务器端
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;
}
}
1.2. Application_Model_WsDetection
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
}
}
2.客户端
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);
}
}
3.调用网络服务:
http://localhost/my_app_site/public/wsclient/detections/?wsdl
4.错误:
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
我希望我已经很好地解释了我的问题,
非常感谢。
(对不起我的英语不好)