WCF Data Service Error – Request Error
Posted by Keith Elder | Posted in .Net, C#, WCF | Posted on 09-03-2010
I’ve done this twice now and I know if I’ve done it others probably have as well. Here’s the short story and the fix.
Let’s say you create a new project to play around with a WCF Data Service to create some OData. You add an entity framework model from an existing database and then add a WCF Data Service. Things are going along nicely. To get something up and running quickly you modify the WCF Data Service to look like the following. All looks good.
1: namespace WcfService2
2: {
3: public class WcfDataService1 : DataService<NutshellEntities>
4: {
5: // This method is called only once to initialize service-wide policies.
6: public static void InitializeService(DataServiceConfiguration config)
7: {
8: // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
9: // Examples:
10: // config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead);
11: // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
12: config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
13: config.SetEntitySetAccessRule("Customer", EntitySetRights.All);
14: }
15: }
16: }
Then you build your solution thinking you are about to strike gold when all of a sudden you are presented with this nasty unhelpful error:
Request Error
The server encountered an error processing the request. See server logs for more details.
The problem lies in line 13. See the string? Yeah, that’s a spot where we as humans have to type something and let’s face it, we make mistakes. I’ve done this several times already. To fix this, look at your model and make sure you have the correct name. Here is my playground model:
Yep, it was suppose to be “Customers” instead of “Customer”. Change line 13 to “Customers” and all is well.
I agree, why don’t you blog about the freckle on your arm?
This was so useless..
To solve that, you should just use a strong typed name. Simple as:
config.SetEntitySetAccessRule(new Customers().GetType().Name, …)
Easy as pie! 😉