ServiceStack ResponseFilterAttribute不会被调用(ServiceS

2019-09-22 06:29发布

//---------------------------------------------------------------------
//Aspect Filters
public class RequestAspectAttribute : RequestFilterAttribute {
  public RequestAspectAttribute() { } //debug point was hit
  public RequestAspectAttribute(ApplyTo applyTo) : base(applyTo) { }
  public override void Execute(IHttpRequest req, IHttpResponse res, object reqDto) {
      //This code is executed before the service 
      //debug point was hit
  }
}
public class ResponseAspectAttribute : ResponseFilterAttribute {
  public ResponseAspectAttribute() { } //debug point was NOT hit
  public ResponseAspectAttribute(ApplyTo applyTo) : base(applyTo) { }
  public override void Execute(IHttpRequest req, IHttpResponse res, object resDto) {
      //This code is executed after the service 
      //debug point was NOT hit
  }
}
//---------------------------------------------------------------------
//REST Service
[RequestAspect]
[ResponseAspect]
public class TodoService : RestServiceBase<Todo> { ...

我测试了与上面的代码中的待办事项列表示例项目/ RES过滤器属性的所需物品。 所以,没有别的已更改为样本项目(我认为),除了两个附加属性。

当我添加一个待办事项,只有请求属性被调用。 响应属性没有被触发。

难道他们不应该火起来之前和在此情况下,REST调用后,一对? 我的理解是不正确或我做错了什么? 谢谢你提前为您的帮助。

Answer 1:

用你的请求和响应滤波器与各自的请求和响应DTO

    [Route("/Hello")]
    [RequestAspect]
    public class HelloRequest
    {
        public string hello { get; set; }
    }
    [ResponseAspect]
    public class HelloResponse
    {
        public string hello { get; set; }
    }
    public class HelloService : Service
    {
        public object Any(HelloRequest req)
        {
            return new HelloResponse
            {
                hello = req.hello
            };
        }
    }


文章来源: ServiceStack ResponseFilterAttribute not being called