问题描述
//---------------------------------------------------------------------
//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筛选属性上与待办事项列表示例项目上面的代码。所以,没有别的已更改为示例项目(我认为),除了这两个附加属性。
I am testing out the Req/Res Filter Attributes on the ToDo List sample project with the code above. So nothing else has been changed to the sample project (I think) except for the two additional attributes.
当我添加一个待办事项,只有请求属性被调用。该响应的属性并没有被触发
When I add a todo item, only the request attribute was called. The response attribute didn't get triggered.
难道他们不应该在一对前和放火起来;之后,在这种情况下REST调用?我的理解是不正确或我做错了什么?谢谢你提前为您的帮助。
Shouldn't they fire up in a pair before & after a Rest call in this case? Is my understanding incorrect or am I doing something wrong? Thank you ahead for your help.
推荐答案
使用您的请求和响应滤波器与各自的请求和响应DTO
Use your request and response filters with respective Request and Response 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不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!