我正在做一些休息和一些SOAP服务,为我使用FOSRestBundle
的REST者,为SOAP型我使用BeSimple Soap Bundle
(这确实没有那么相关,因为问题出在FOSRest
听众IMO,但我只是为了以防万一)。冲突
的事情是FOSRest
提供了一个监听器来处理响应和序列化/使其像这样:
<?php
/**
* @Rest\View
*/
public function getAction()
{
return $item;
}
,它处理其序列为JSON/XML
或任何响应。 当我尝试调用我的SOAP服务时,冲突出现,并且侦听器对我说,它不支持SOAP
作为格式(它支持JSON,XML等)。
发生这种情况时,我把view_response_listener: 'force'
放到我的FOSRest yml配置文件中。如果我将其更改为view_response_listener: 'enabled'
,则SOAP服务可以正常工作,但我似乎失去了自动处理我的响应的FOSRest功能。
我怎样才能确定FOSRest view_response_listener
只是处理了正确的回答,让SOAP Bundle
处理肥皂类型的回应。
编辑:
fos_rest:
param_fetcher_listener: true
body_listener: true
format_listener: true
view:
view_response_listener: 'force' #This is the parameter that is driving me crazy. Value to 'force' Rest controllers work just fine SOAP don't, value to 'enabled' the other way around
formats:
xml: true
json : true
templating_formats:
html: true
force_redirects:
html: true
failed_validation: HTTP_BAD_REQUEST
default_engine: twig
routing_loader:
default_format: json
这是FOSRestBundle
配置。
这里是我的routing.yml
为休息端点和SOAP的人都:
#config/routing.yml
rest_api:
resource: "@RESTBundle/Resources/config/api_routes.yml"
host: "%host_front%" #api.myproject.local
type: rest
#api_routes.yml detail
accounts:
resource: 'RESTBundle\Controller\AccountsController'
type: rest
name_prefix: api_
#config/routing.yml
soap_api:
resource: "@SOAPBundle/Resources/config/soap_routing.yml"
host: "%host_ws%"
prefix: "%contexto_ws%"
#soap_routing.yml detail
_besimple_soap:
resource: "@BeSimpleSoapBundle/Resources/config/routing/webservicecontroller.xml"
soap_ws:
resource: "@SOAPBundle/Controller/"
type: annotation
RestController例如:
<?php
namespace RESTBundle\Controller\API;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\FOSRestController;
use Nelmio\ApiDocBundle\Annotation\ApiDoc as ApiDoc;
use Symfony\Component\HttpFoundation\Request;
/**
* @Rest\RouteResource("accounts", pluralize=false)
*/
class AccountsController extends FOSRestController
{
/**
* @Rest\View
*/
public function getAction($userId)
{
return [
['name' => 'Example', 'pass'=> 'example'],
['name' => 'Example2', 'pass'=> 'example2']
];
}
}
SOAP控制器:
/**
* @Soap\Header("user", phpType="string")
* @Soap\Header("token", phpType="string")
*/
class AccountsController implements ContainerAwareInterface
{
use ContainerAwareTrait;
/**
* @Soap\Method("getAccounts")
* @Soap\Param("account", phpType="SOAPBundle\DataType\AccountFilter")
*
* @Soap\Result(phpType="SOAPBundle\DataType\Account[]"")
*/
public function getAccountsAction(Request $request, AccountFilter $filter)
{
return [(new Account())->setName('Example')->setPass('example')] //This is just an example
}
}
编辑与错误:
request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException: "Format 'soap' not supported, handler must be implemented" at /home/teampro/Sites/corinto/vendor/friendsofsymfony/rest-bundle/View/ViewHandler.php line 292 {"exception":"[object] (Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException(code: 0): Format 'soap' not supported, handler must be implemented at /.../vendor/friendsofsymfony/rest-bundle/View/ViewHandler.php:292)"} []
请'config'更新您的问题路由配置,这是很难阅读各行:)另外,你可以分享你的代码吗? – Samundra
@Samundra完成,它不是我的代码(不能在这里发布),但它是一个基于它的虚拟示例,所以它叫同样的东西。 – Astaroth