WCF 数据服务:截获所有查询

本文关键字:查询 数据 服务 WCF | 更新日期: 2023-09-27 17:56:54

我一直在尝试通过开发基于多个条件标识客户端的自定义每会话身份验证机制来保护我的 WCF 数据服务。然后我想根据此身份验证的结果拦截所有查询和非查询请求。拦截查询没有问题,但由于我可能有很多表,我一直在寻找一种方法来拦截所有查询都在同一个地方。

例如,代替

[QueryInterceptor("Entities")]
public Expression<Func<Entity, Boolean> FilterEntities(){
    return x=> IsAuthenticated;
}

行为

[QueryInterceptor("*")]
public Expression<Func<T, Boolean> FilterEntities<T>(){
    return x=> IsAuthenticated;
} // As a logical description only, of course it won't work as it is

那么有没有办法过滤WCF数据服务中的所有查询和非查询请求呢?

WCF 数据服务:截获所有查询

看起来目前无法使用

QueryInterceptor,您必须手动添加每个实体集名称:https://github.com/OData/odata.net/blob/ODATAV3/WCFDataService/Service/System/Data/Services/DataServiceStaticConfiguration.cs#L188

但是,您可以参考此博客系列,了解如何在 WCF 数据服务中执行身份验证。http://blogs.msdn.com/b/odatateam/archive/2010/07/21/odata-and-authentication-part-6-custom-basic-authentication.aspx