Search code examples
c#entity-frameworkwcf-data-services

In WCF Data Services, how do I use SetServiceOperationAccessRule with remote Assemblies


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?


Solution

  • 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.