我正在Symfony应用程序中构建一个Soap服务器.作为第一步,我使用“hello world”Soap动作创建了一个控制器并为其定义了路径:
原文链接:https://www.f2er.com/php/134151.html使用routing.yml
api.soap.foo path: /soapapi/foo defaults: { _controller: SoapBundle\Controller\FooController:bar } methods: [GET,HEAD,POST]
FooController的#巴(…)
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; }
现在,当我在浏览器中调用http://my-app.loc/soapapi/foo/bar或使用cURL(通过HTTP GET)时,我收到一个错误:
<?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>
但是当我调用http://my-app.loc/soapapi/foo/bar?wsdl时,我实际上得到了(生成的)WSDL文档.为什么?我没有定义任何地方,它应该像这样工作.为什么以及如何(魔术)起作用?这是Symfony特有的魔力吗?