How to create WCF data service from existing data base model or custom class

Thread is closed for posting
1 posts, 0 answers
  1. 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 13 Nov 2013 Link to this post

    Requirements

    RadControls version 2013.3.1015.40
    .NET version 4.0
    Visual Studio version
    programming language C#
    browser support

    all browsers supported by RadControls


    PROJECT DESCRIPTION

    This code library shows how you can create Wcf service to expose an existing data base data or custom class data. Let me give you the basic steps for implementing both scenarios:

    Using entity model of an existing data base:

    1. Create a ADO.NET Entity model and select the data base file and the tables you want to map
    2. Create a WCF data service. Please use the [JSONPSupportBehavior] attribute when the requests need to be cross domain.
      [JSONPSupportBehavior]
      public class NorthwindService : DataService<NorthwindEntities>
    3. Please use the NorthWind entities as shown:
      public class NorthwindService : DataService<NorthwindEntities>
    4. In the InitializeService method please set which entity set to expose. In this case this the Employees:
      public static void InitializeService(DataServiceConfiguration config)
              {        
                  config.SetEntitySetAccessRule("Employees", EntitySetRights.AllRead);        
                  config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
              }

    2.        Using custom class data is pretty similar:

    1. Create a class that represents your custom data in this case – Continent class
    2. Create a ContinentContext class to return IQueryable<Continent>
      public class ContinentService : DataService<ContinentsContext>
    3. In the InitializeService method please set which entity set to expose. In this case this the Continents:
      public static void InitializeService(DataServiceConfiguration config)
              {
                  config.SetEntitySetAccessRule("Continents", EntitySetRights.AllRead);
                  config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
              }

    The following resouorces might be helpful:
Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.