Question

I've got a problem with the native php SoapServer in symfony2. The SoapServer uses a "UserService" Service-Class in symfony2, which should be instantiated with the symfony2 EntityManager injected so that I can get access to my "UserRepository".

To clarify:

Soap-Server:

$oSOAPServer = new \SoapServer('/path/to/wsdl');
$oSOAPServer->setClass("my\Namespace\UserService");
$oSOAPServer->handle();

Service:

use \Doctrine\ORM\EntityManager as EntityManager;

class UserService
{
    protected $em;
    public function __construct(EntityManager $em) {
        $this->em = $em;
    }
...

Problem is: the SoapServer always returns an Internal Server Error. The service itself works called in symfony2 directly. Is it even possible to inject the EntityManager when called/instantiated by the SoapServer?

Thanks in advance!

Martin

Was it helpful?

Solution

Instead of using SoapServer::setClass() you could use SoapServer::setObject() and pass your service in:

$oSOAPServer = new \SoapServer('/path/to/wsdl');
$oSOAPServer->setObject($container->get('my_service'));
$oSOAPServer->handle();

Implementing a soap server is documented in the Symfony documentation: How to Create a SOAP Web Service in a Symfony2 Controller

Also, if you only need a repository, don't inject the whole entity manager. Register your repository as a service and inject it to your service.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top