在 WCF 数据服务中,如何将 SetServiceOperationAccessRule 与远程程序集一起使用
假设我的 EF4 实体是 MyClass,集名称是 MyClasses。
它们都在 MyNamespace 命名空间中,所以: MyNamespace.MyClass
所以我有这样一行:
config.SetServiceOperationAccessRule("MyClasses",
ServiceOperationRights.AllRead);
但后来我得到这个错误:
The given name 'MyClasses' was not found in the service operations.
Parameter name: name
所以我尝试了这个:
config.SetServiceOperationAccessRule("MyNamespace.MyClass",
ServiceOperationRights.AllRead);
和这个:
config.SetServiceOperationAccessRule("MyNamespace.MyClasses",
ServiceOperationRights.AllRead);
但是,同样的错误...
我的实体和数据上下文位于一个单独的组件。这有关系吗?
如何正确指定集合?
Let's pretend my EF4 entity is MyClass, and the set name is MyClasses.
They are both in the MyNamespace namespace, so: MyNamespace.MyClass
So I have a line like this:
config.SetServiceOperationAccessRule("MyClasses",
ServiceOperationRights.AllRead);
But then I get this error:
The given name 'MyClasses' was not found in the service operations.
Parameter name: name
So I tried this:
config.SetServiceOperationAccessRule("MyNamespace.MyClass",
ServiceOperationRights.AllRead);
and this:
config.SetServiceOperationAccessRule("MyNamespace.MyClasses",
ServiceOperationRights.AllRead);
But, same error...
My entties and data context are in a seperate assembly. Does that matter?
How do you specify the set correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试:
其中
MyAssemblyName
是定义MyClass
的程序集的名称。Try:
where
MyAssemblyName
is name of the assembly whereMyClass
is defined.有时,实体模型会生成带有 (s) 的实体,例如,产品表是使用“Products”名称创建的,或者创建的产品不带“'s”
Some times the entity model generate the entities with (s), for example, product table are create with "PRODUCTs" name or PRODUCT without ''s"
它们位于不同的程序集中并不重要。重要的是实体集和服务操作之间的区别。
如果您有一个名为 MyClasses 的实体集(对于 EF,这通常是“表”名称,并作为上下文中的属性公开),那么您需要使用 config.SetEntitySetAccessRule 方法。
如果您有服务操作(这将是派生自 DataService 的类上的方法),那么您需要使用 config.SetServiceOperationAccessRule。
It shouldn't matter that they are in a different assembly. What does matter is the difference between entity sets and service operations.
If you have an entity set (with EF this is usually the "table" name, and is exposed as a property on the context) called MyClasses, then you need to use config.SetEntitySetAccessRule method.
If you have a service operation (that would be a method on the class which derives from DataService), then you need to use config.SetServiceOperationAccessRule.