I was trying out VS2010 RC WCF Data Service Reference today, and did the following:

1. Create a web application project, build, no problem

2. Add a ADO.NET Entity Data Model, referencing to NorthWind database, build, no problem

3. Add a WCF Data Service (In VS2008, we called it ADO.NET Data Service), And changed to the following, build, no problem.

public class WcfDataService1 : DataService< NorthWindEntities2   >
{
    // This method is called only once to initialize service-wide policies.
    public static void InitializeService(DataServiceConfiguration config)
    {
        // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
        // Examples:
        //config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
        //config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
    }
}

4. Add another web application project to the solution, add service reference, discover, double click the above service that was found automatically

5. Build 2nd project

Error!

Error    1    'WebApplication2.ServiceReference1.NorthWindEntities2.OnContextCreated()' is abstract but it is contained in non-abstract class 'WebApplication2.ServiceReference1.NorthWindEntities2'    d:\users\fwtlaba\documents\visual studio 2010\Projects\WebApplication1\WebApplication2\Service References\ServiceReference1\Reference.cs    30    30    WebApplication2

I checked through the bug database, yes, it’s a known problem that not going to be fixed, but with little information on how to workaround it.  Just saying it going to happen if there is no entity exposed in the service. 

Thinking hard, and finally I realized that I forget to uncomment the config.SetEntitySetAccessRule and config.SetServiceOperationAccessRule lines in the above code.  Once I uncomment those 2 lines, rebuild the 1st application, and update the service reference in the 2nd web application, I can build the 2nd web application without errors now.

I never found it before because I always uncomment those 2 lines.  It’s a bit scary at first.  So I write this blog in case any one else encounter it later when VS2010 ships.

 

Enjoy Visual Studio…

 

Xinyang Qiu