0
jaq316 created
I have an application service that is called by an external service and this service requires the response to be a specific XML format. How can I add a custom action filter to return the correct XML response?
My code currently looks like this:
DynamicApiControllerBuilder
.For<ISomeAppService>("app/some")
.ForMethod("Process")
.WithVerb(Abp.Web.HttpVerb.Get)
.WithFilters(/* ??? How do I modify the response using a custom action filter? *?)
.Build();
4 Answer(s)
-
0
40 views but no response?
-
0
Maybe no one knows :)
I don't know how to make it with filters. Can you create such a filter for regular Web API controllers (out of ABP)?
-
0
For anyone that wants to do the same... Here is the solution:
- Create the filter class:
public class PlainTextResponseActionFilter : ActionFilterAttribute, IActionFilter, IFilter { public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) { var abpAjaxContent = actionExecutedContext.Response.Content as ObjectContent<Abp.Web.Models.AjaxResponse>; if (abpAjaxContent != null) { var previousValue = abpAjaxContent.Value as Abp.Web.Models.AjaxResponse; actionExecutedContext.ActionContext.Response.Content = new StringContent(previousValue.Result.ToString()); } else base.OnActionExecuted(actionExecutedContext); } }
- Reference the class in the WithFilters method of the DynamicApicontrollerBuilder
DynamicApiControllerBuilder .For<ISomeAppService>("app/some") .ForMethod("Process") .WithVerb(Abp.Web.HttpVerb.Get) .WithFilters(new PlainTextResponseActionFilter()) .Build();
-
0
Thank you for this valuable information sharing :)