0

I have implemented a webservice using ZF (tutorial : http://benjaminprevot.fr/2010/06/16/produire-un-webservice-soap-avec-zend-framework/ [french])

the original tutorial works fine,
but I dont know why when i call getDetections() in the server side the framework raise an exception.

Code:

1.1. sever side

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. Client side

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. Call the webservice :

http://localhost/my_app_site/public/wsclient/detections/?wsdl

4. The Error:

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

I hope that I have well explained my problem
many thanks.
(excuse me for my bad english)

Community
  • 1
  • 1
Salem
  • 331
  • 1
  • 7
  • 21

1 Answers1

0

Are you able to instantiate an Application_Model_Detection object anywhere outside of getDetections()?
If yes, then perhaps the problem is Zend's autoloader not working properly within the core SoapClient::__soapCall() method. (Or within the call_user_func() that happens within that.) You might be able to fix it by adding a

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

In any case, I suspect it is an autoloader namespace problem. Your 'Application_' prefix has special meaning to Zend, so make sure that the class is able to be instantiated.

ByteNudger
  • 1,545
  • 5
  • 29
  • 37
Seth Battin
  • 2,811
  • 22
  • 36