Featured Post

VirtualBox Hangs During Installation – Close DropBox

I spent several days off and on trying to get VirtualBox to install (version 4.0.2 to be exact).  After numerous things I started shutting down everything to see what was going on.  Turns out after I shut down DropBox the install proceeded.  Up until that point it would only get to about 85% of the...

Read More

WCF Data Service Error – Request Error

Posted by Keith Elder | Posted in .Net, C#, WCF | Posted on 09-03-2010

3

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:

image

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:

image

Yep, it was suppose to be “Customers” instead of “Customer”. Change line 13 to “Customers” and all is well.