I am creating a Soap server in a Symfony application. As a first step, I created a controller with my "hello world" Soap action and defined a route for it:
routing.yml
api.soap.foo path: /soapapi/foo defaults: { _controller: SoapBundle\Controller\FooController:bar } methods: [GET, HEAD, POST]
FooController#bar(...)
protected function bar(Request $request) { $autodiscover = new AutoDiscover(); $autodiscover ->setClass(MyFooBarService::class) ->setUri('http://my-app.loc/soapapi/foo/bar') ->setServiceName('MyFooBarService') ; $wsdl = $autodiscover->generate(); $wsdl->dump(__DIR__ . '/soapapi-foo-bar.wsdl'); $server = new SoapServer(__DIR__ . '/soapapi-foo-bar.wsdl'); $server->setObject($this->myFooBarService); $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; }
Now, when I call http://my-app.loc/soapapi/foo/bar
in the browser or using cURL (so via HTTP GET), I get the error message:
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode>SOAP-ENV:Client</faultcode> <faultstring>Bad Request</faultstring> </SOAP-ENV:Fault> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
But when I call http://my-app.loc/soapapi/foo/bar?wsdl
, I actually get a (generated) WSDL document. What for? I haven’t decided anywhere that he should work like that. Why and how does this (magic) work? Is this special symfony magic?
source share