C# 在WCF数据服务中,如何对远程程序集使用SetServiceOperationAccessRule

C# 在WCF数据服务中,如何对远程程序集使用SetServiceOperationAccessRule,c#,entity-framework,wcf-data-services,C#,Entity Framework,Wcf Data Services,让我们假设我的EF4实体是MyClass,集合名是MyClass 它们都在MyNamespace名称空间中,因此:MyNamespace.MyClass 我有一句话是这样的: config.SetServiceOperationAccessRule("MyClasses", ServiceOperationRights.AllRead); 但是我得到了这个错误: The given name 'MyClasses' was not found in the service opera

让我们假设我的EF4实体是MyClass,集合名是MyClass

它们都在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);
但是,同样的错误

我的条目和数据上下文在一个单独的程序集中。那有关系吗

如何正确指定集合?请尝试:

config.SetServiceOperationAccessRule("MyNamespace.MyClass, MyAssemblyName", 
    ServiceOperationRights.AllRead);

其中
MyAssemblyName
是定义了
MyClass
的程序集的名称。

它们位于不同的程序集中并不重要。重要的是实体集和服务操作之间的差异。 如果您有一个名为MyClasses的实体集(使用EF,这通常是“表”名称,并在上下文中作为属性公开),那么您需要使用config.SetEntitySetAccessRule方法。
如果您有一个服务操作(这将是从DataService派生的类上的一个方法),那么您需要使用config.SetServiceOperationAccessRule。

有时实体模型会生成带有的实体,例如,创建带有“PRODUCTs”名称的产品表或不带“s”的产品