肥皂服务器Symfony如何设置响应

问题描述:

我想在Symfony3中实现一个非常简单的soap调用。 它完美的作品,但它什么都不返回。肥皂服务器Symfony如何设置响应

在我的控制器中我只是这样称呼它

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

和被调用函数看起来像这样

public function hello($param) 
{ 
    return 'Hello, '.$param->name; 
} 

我用了SoapUI尝试过了,它完美的作品,但肥皂回报是像这

<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> 

它不会返回这样的函数的响应

<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> 

我该如何归还?

我终于找到了问题。我只需要改变我在hello函数中返回的方式。 它现在看起来像这样,效果很好。

public function hello($param) 
{ 
    $response = array(); 
    $response['out']='Hello, '.$param->name; 
    return $response; 
}