想要覆盖 WCF 中为 EntityType 数据返回的内容
我在模型中定义了一个名为 SessionsOverview
的实体。我通过 WCF 服务公开它,代码如下:
public static void InitializeService(DataServiceConfiguration config)
{
// Examples:
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.AllRead);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
它在名为 ModelSessionView.Designer.cs
的文件中创建一堆代码。
在该代码中,它当前有一个名为 SessionsOverviews< 的方法。 /code> 返回一个 .net 对象。我想根据一些安全规则覆盖返回的内容。具体来说,我想查看我的 app.config,获取一个设置,如果该设置不正确,我想隐藏此对象中的一些数据。我可以开始更新这个文件,但这似乎是错误的。有一个明确的地方我应该添加这样的逻辑吗?
谢谢
/// <summary>
/// No Metadata Documentation available.
/// </summary>
public ObjectSet<SessionsOverview> SessionsOverviews
{
get
{
if ((_SessionsOverviews == null))
{
_SessionsOverviews =
base.CreateObjectSet<SessionsOverview>("SessionsOverviews");
}
return _SessionsOverviews;
}
}
I've got an entity defined called SessionsOverview
in my model. I expose it through a WCF service with code like the following:
public static void InitializeService(DataServiceConfiguration config)
{
// Examples:
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.AllRead);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
It creates a bunch of code in a file called ModelSessionView.Designer.cs
In that code, it currently has a method called SessionsOverviews
that returns a .net object. I'd like to override what is returned based on some security rules. Specifically, I want to look in my app.config, get a setting, and if that setting is not true, I want to hide some of the data in this object. I could just start updating this file, but that seems wrong. Is there a clear place I should add logic like this?
Thanks
/// <summary>
/// No Metadata Documentation available.
/// </summary>
public ObjectSet<SessionsOverview> SessionsOverviews
{
get
{
if ((_SessionsOverviews == null))
{
_SessionsOverviews =
base.CreateObjectSet<SessionsOverview>("SessionsOverviews");
}
return _SessionsOverviews;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尝试过使用 QueryInterceptor 吗?
这些在服务类上指定并返回一个您可以自己编写的表达式。
一个简单的例子定义如下:
此外,您还可以指定 ChangeInterceptors。
有关详细信息,请参阅以下文章
http://msdn.microsoft.com/en-我们/library/dd744842.aspx
Have you tried using QueryInterceptor's?
These get specified on the service class and return an expression that you can write your self.
A simple example is defined below:
Additionally you can also specify ChangeInterceptors.
See the following article for further details
http://msdn.microsoft.com/en-us/library/dd744842.aspx