4
//---------------------------------------------------------------------
//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> { ...

我正在使用上面的代码测试 ToDo List 示例项目中的 Req/Res 过滤器属性。因此,除了两个附加属性外,示例项目(我认为)没有任何其他更改。

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

在这种情况下,他们不应该在休息呼叫之前和之后成对启动吗?是我的理解不正确还是我做错了什么?提前感谢您的帮助。

4

1 回答 1

0

将您的请求和响应过滤器与相应的请求和响应 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
            };
        }
    }
于 2014-08-19T05:37:51.207 回答