How does this work with the WSDL URI request parameter?

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?

+6
source share
1 answer

This is a great question.

No, this does not apply to Symfony, this is the behavior of the embedded SOAP server in PHP. When the added ?wsdl is added to the ?wsdl , the SOAP server will respond using the wsdl document with which it was created in the constructor:

 $server = new SoapServer(__DIR__ . '/soapapi-foo-bar.wsdl'); 

I was not able to find where this behavior is documented on the PHP website, but it clearly exists and is reproducible.

The code for the function can be found in the PHP source code, starting with line 1550 and ending with line 1592. The code checks the request method is GET and checks for the presence of the wsdl request parameter.

+2
source

Source: https://habr.com/ru/post/1013998/


All Articles