diff --git a/EventListener/SoapResponseListener.php b/EventListener/SoapResponseListener.php new file mode 100644 index 0000000..57e23e0 --- /dev/null +++ b/EventListener/SoapResponseListener.php @@ -0,0 +1,56 @@ + + * (c) Francis Besset + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace BeSimple\SoapBundle\EventListener; + +use BeSimple\SoapBundle\Soap\SoapRequest; +use BeSimple\SoapBundle\Soap\SoapResponse; +use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; + +/** + * SoapResponseListener. + * + * @author Francis Besset + */ +class SoapResponseListener +{ + /** + * @var SoapResponse + */ + protected $response; + + /** + * Constructor. + * + * @param SoapResponse $response The SoapResponse instance + */ + public function __construct(SoapResponse $response) + { + $this->response = $response; + } + + /** + * Set the controller result in SoapResponse. + * + * @param GetResponseForControllerResultEvent $event A GetResponseForControllerResultEvent instance + */ + public function onKernelView(GetResponseForControllerResultEvent $event) + { + $request = $event->getRequest(); + if (!$request instanceof SoapRequest) { + return; + } + + $this->response->setReturnValue($event->getControllerResult()); + $event->setResponse($this->response); + } +} diff --git a/Resources/config/webservice.xml b/Resources/config/webservice.xml index ae07e99..122cd86 100644 --- a/Resources/config/webservice.xml +++ b/Resources/config/webservice.xml @@ -5,6 +5,7 @@ BeSimple\SoapBundle\Soap\SoapResponse + BeSimple\SoapBundle\EventListener\SoapResponseListener BeSimple\SoapBundle\WebServiceContext BeSimple\SoapBundle\ServiceBinding\RpcLiteralRequestHeaderMessageBinder BeSimple\SoapBundle\ServiceBinding\RpcLiteralRequestMessageBinder @@ -20,6 +21,11 @@ + + + + + diff --git a/Resources/doc/soapserver/configuration.rst b/Resources/doc/soapserver/configuration.rst index 0549b4b..ee3c7bc 100644 --- a/Resources/doc/soapserver/configuration.rst +++ b/Resources/doc/soapserver/configuration.rst @@ -34,7 +34,7 @@ Annotations for Controllers .. code-block:: php - namespace My\App\Controller; + namespace Acme\DemoBundle\Controller; use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap; use Symfony\Component\DependencyInjection\ContainerAware; @@ -48,7 +48,17 @@ Annotations for Controllers */ public function helloAction($name) { - return $this->container->get('besimple.soap.response')->setReturnValue(sprintf('Hello %s!', $name)); + return sprintf('Hello %s!', $name); + } + + /** + * @Soap\Method("goodbye") + * @Soap\Param("name", phpType = "string") + * @Soap\Result(phpType = "string") + */ + public function goodbyeAction($name) + { + return $this->container->get('besimple.soap.response')->setReturnValue(sprintf('Goodbye %s!', $name)); } } @@ -57,5 +67,4 @@ Get your WSDL To access your WSDL go to the following address: http://localhost/app_dev.php/ws/DemoApi?wsdl -To read the WSDL in your browser you can call this address: http://localhost/app_dev.php/ws/DemoApi - +To read the WSDL in your browser you can call this address (without `wsdl` parameter): http://localhost/app_dev.php/ws/DemoApi