gavec
gavec

Reputation: 205

SOAP server in Symfony 2 project

Im trying to implement WebService using SOAP in Symfony 2 framework. On server side im setting class to my server (setClass() method) becouse i need to make more operations on one instance of class. If i used setObject for soapCalls, it works good,

use path\to\Test;
public function indexAction()
{
    $server = new \SoapServer(null, array('uri' => "http://test-uri.cz/"));
    $server->setObject($this->get('my_service'));
    $response = new Response();
    $response->headers->set('Content-Type', 'text/xml');

    ob_start();
    $server->handle();
    if (ob_get_length() > 0) {
        $response->setContent(ob_get_clean());
    }

    return $response;
}

but doesn`t work with setClass method.

use path\to\Test;
public function indexAction()
{
    $server = new \SoapServer(null, array('uri' => "http://test-uri.cz/"));
    $server->setClass('Test');
    $response = new Response();
    $response->headers->set('Content-Type', 'text/xml');

    ob_start();
    $server->handle();
    if (ob_get_length() > 0) {
        $response->setContent(ob_get_clean());
    }

    return $response;
}

Can somebody gives me any hints?

Upvotes: 1

Views: 1619

Answers (2)

gavec
gavec

Reputation: 205

Finally it works... I had bad namespace and in SOAP server is need to use setPersistence() method after setClass().

Upvotes: 1

AlterPHP
AlterPHP

Reputation: 12717

If you want to use SoapServer::setClass, you must state each parameters of the constructor of your service, and state the class name with a full namespaced string :

$server->setClass('Acme\YourBundle\SoapManager', $arg0, $arg1, $arg2 /*, ... */);

Upvotes: 1

Related Questions