I am trying to implement a very simple soap call in Symfony3. It works perfectly but it return nothing.
In my controller I just call it like this
public function indexAction()
{
$server = new \SoapServer($this->get('kernel')->getRootDir()."/../web/soap/test.wsdl");
$server->setObject($this->get('serv.soapservice'));
$response = new Response();
$response->headers->set('Content-Type', 'text/xml; charset=ISO-8859-1');
ob_start();
$server->handle();
$response->setContent(ob_get_clean());
return $response;
}
And the called function looks like this
public function hello($param)
{
return 'Hello, '.$param->name;
}
I tried it with SoapUI and it works perfectly, but the soap return is like this
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/symfony/test/web/app_dev.php/en/soap">
<SOAP-ENV:Body>
<ns1:helloResponse/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
It doesn't return the response of the function like this
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/symfony/test/web/app_dev.php/en/soap">
<SOAP-ENV:Body>
<ns1:helloResponse>
<out>Hello John</out>
<ns1:helloResponse/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
How can I return it?
I finally find the problem. I just have to change the way I return in my hello function. It looks like this now and works great.
public function hello($param)
{
$response = array();
$response['out']='Hello, '.$param->name;
return $response;
}