Home » Php » php – How does it work with the magic WSDL URI query parameter?

php – How does it work with the magic WSDL URI query parameter?

Posted by: admin July 12, 2020 Leave a comment


I’m building a Soap server within a Symfony application. As first step I created a controller with my “hello world” Soap action and defined the route for it:


    path: /soapapi/foo
    defaults: { _controller: SoapBundle\Controller\FooController:bar }
    methods: [GET, HEAD, POST]


protected function bar(Request $request)
    $autodiscover = new AutoDiscover();
    $wsdl = $autodiscover->generate();
    $wsdl->dump(__DIR__ . '/soapapi-foo-bar.wsdl');
    $server = new SoapServer(__DIR__ . '/soapapi-foo-bar.wsdl');
    $response = new Response();
    $response->headers->set('Content-Type', 'text/xml; charset=ISO-8859-1');
    return $response;

Now, when I call http://my-app.loc/soapapi/foo/bar in a browser or using cURL (so via HTTP GET), I get an error:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
            <faultstring>Bad Request</faultstring>

But when I call http://my-app.loc/soapapi/foo/bar?wsdl, I actually get the (generated) WSDL document. Why? I have not defined anywhere, that it should work like this. Why and how does this (magic) work? Is it Symfony specific magic?

How to&Answers:

This is a great question.

No this is not Symfony specific, it’s a behavior of the built-in SOAP server in PHP. When the endpoint URL is accessed with ?wsdl appended, the SOAP server will respond with the wsdl document that it was instantiated with in the constructor:

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

I haven’t been able to find where this behavior is documented on the PHP website, but it clearly exists and is reproducible.

The code for the feature can be found in PHP’s source code starting on line 1369 and ending on line 1396. The code checks if the request method is GET and checks for the presence of a ‘wsdl’ query parameter.