0

我已经使用 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

我希望我已经很好地解释了我的问题,
非常感谢。
(对不起我的英语不好)

4

1 回答 1

0

你能Application_Model_Detection在 之外的任何地方实例化一个对象getDetections()吗?如果是,那么问题可能是 Zend 的自动加载器在核心方法中
无法正常工作。SoapClient::__soapCall()(或者在call_user_func()那个发生的那个范围内。)你可以通过添加一个来修复它

require_once("{full path to Application_Model_Detection file}");

无论如何,我怀疑这是一个自动加载器命名空间问题。您的“Application_”前缀对 Zend 具有特殊意义,因此请确保该类能够被实例化。

于 2012-07-06T21:06:26.257 回答