Data Access has been discontinued. Please refer to this page for more information.

Creating WCF Data Service

This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.

In this task is demonstrated how to create a WCF Data Service by using the Service Wizard.

The topics in this section form a walkthrough, and each topic builds on the previous one. At the end of each topic, you will have a functional application.

Creating WCF Data Service

To create a new WCF Data Service:

  1. Build your solution.
  2. Right-click the SofiaCarRentalDomainModel.rlinq and select Add Telerik Data Access Service....

  3. This will bring up the Service Wizard. The first page of the wizard is the Select Source and Output dialog. From the Select context drop-down select SofiaCarRentalDbContext. From the Host in Project drop-down select SilverlightOpenAccessIntegration. Check the Use Existing Project option and select SilverlightOpenAccessIntegration.

  4. Click Next to continue. The Select Service Type dialog appears. Select WCF Data Service - OData v3.

  5. Click Next to continue. In the Service Configuration dialog, set the Service Name to SofiaCarRentalWCFDataService. Select which entities from the grid below to be generated as part of the service. By default all entities are selected. Also you have the option to specify what CUD operations can be performed on the generated entities. Check all entities.

  6. Click Next to continue. In the Preview dialog, review all changes that will be done in your project.

  7. Click Finish to generate the service.

  8. The Service Wizard performs the following steps:

    1. Sets references to all of the WCF Data Services libraries.
    2. Sets references to the Telerik Data Access DLLs.
    3. And last, the wizard creates the actual service files (.svc and .cs).

      [System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
      public partial class SofiaCarRentalWCFDataService :
        OpenAccessDataService<OA.SL.WcfData.Demo.Web.SofiaCarRentalDbContext>
      {
      /// <summary>
      /// Initializes the service.
      /// </summary>
      /// <param name="config">The configuration object.</param>
      public static void InitializeService(DataServiceConfiguration config)
      {
         config.SetEntitySetAccessRule("RentalRates", EntitySetRights.All);
         config.SetEntitySetAccessRule("RentalOrders", EntitySetRights.All);
         config.SetEntitySetAccessRule("Employees", EntitySetRights.All);
         config.SetEntitySetAccessRule("Customers", EntitySetRights.All);
         config.SetEntitySetAccessRule("Categories", EntitySetRights.All);
         config.SetEntitySetAccessRule("Cars", EntitySetRights.All);
         // TODO: Set service behavior configuration options
         // Examples:
         // config.DataServiceBehavior.AcceptCountRequests = true;
         // config.DataServiceBehavior.AcceptProjectionRequests = true;
         config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
      }
      }
      
      <System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults:=True)> _
      Partial Public Class SofiaCarRentalWCFDataService
         Inherits OpenAccessDataService(Of OA.SL.WcfData.Demo.Web.SofiaCarRentalDbContext)
         Public Shared Sub InitializeService(ByVal config As DataServiceConfiguration)
             config.SetEntitySetAccessRule("RentalRates", EntitySetRights.All)
             config.SetEntitySetAccessRule("RentalOrders", EntitySetRights.All)
             config.SetEntitySetAccessRule("Employees", EntitySetRights.All)
             config.SetEntitySetAccessRule("Customers", EntitySetRights.All)
             config.SetEntitySetAccessRule("Categories", EntitySetRights.All)
             config.SetEntitySetAccessRule("Cars", EntitySetRights.All)
             ' TODO: Set service behavior configuration options
             ' Examples:
             ' config.DataServiceBehavior.AcceptCountRequests = true
             ' config.DataServiceBehavior.AcceptProjectionRequests = true
             config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3
         End Sub
      End Class
      

Testing the Data Service

To test the data service in a Web Browser, right-click on the .svc file and select View in Browser.