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

时间:2015-06-18 00:28:11

标签: c# wcf wcf-data-services queryinterceptor

我一直在尝试通过开发基于多个条件识别客户端的自定义会话身份验证机制来保护我的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数据服务中过滤所有查询和非查询请求?

1 个答案:

答案 0 :(得分:0)

现在看起来使用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