Настройка SOAP веб-сервиса с использованием Zend Framework в PHP - PullRequest
1 голос
/ 26 ноября 2011

Я пытаюсь настроить веб-сервис, используя стандартный проект Zend Framework.

Error

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());
    }
}

библиотека / Webservice / 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 Project, а не когда он снаружи?

Любая помощь будет высоко ценится. Я рву свои волосы!

Ответы [ 2 ]

0 голосов
/ 05 марта 2013
public function webserviceAction(){
     $this->_helper->layout->disableLayout();`enter code here`       
    $this->_helper->viewRenderer->setNoRender(true);
    //Set up the Web Service
        $auto = new Zend_Soap_Server(null, array(
        'uri' => 'http://localhost/webservice/webservice'
    ));
        $auto->setClass('Webservice_Manager');
        $auto->handle();
}
0 голосов
/ 18 марта 2012

Попробуйте изменить indexAction на Zend_Soap_Server.Это не автообнаружение, но работа выполнена.

public function indexAction()
{
    $this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender(true);

    //Set up the Web Service Manager
    $auto = new Zend_Soap_Server(null, array(
        'uri' => 'http://localhost/webservice/index'
    ));
    $auto->setClass('Webservice_Manager');
    $auto->handle();
}
...