New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Client Binding to WCF Web Service and ADO.NET Data Service

As of ASP.NET 3.5, the .NET framework introduces two new ways to supply data to your ASP.NET server controls - binding to Windows Communication Foundation (WCF) Web Service and binding to ADO.NET Data Services. They allow the developer to use asynchronous calls using these types of services to retrieve data, return it back to the client and update the state of controls based on the result which is send back from the service. Below are a couple of tutorials which include step by step directions how to configure WCF service and ADO.NET Data Services with Visual Studio:

WCF services getting started tutorial

Using Microsoft ADO.NET Data Services

RadGrid for ASP.NET AJAX exposes declarative way to binding itself to data returned from WCF web service or ADO.NET Data Service which is presented in the following online demo of the product. Additionally, both grids from the example support paging/sorting/filtering without any extra coding.

Binding RadGrid for ASP.NET AJAX to WCF Web Service

For the first RadGrid, which is bound to WCF Web Service, you need to specify an existing web service and method with following signature:

ASP.NET
<ClientSettings>
    <DataBinding SelectMethod="GetDataAndCount" Location="GridWcfService.svc"
        SortParameterType="Linq" FilterParameterType="Linq">
    </DataBinding>
</ClientSettings>

where *ResultData *is custom class that holds data returned from the service to client.The signature of this class and the GridWcfService.svc file (used in the demo) are shown below:

ASP.NET
<%@  servicehost language="C#" debug="true" service="GridWcfService" codebehind="~/App_Code/GridWcfService.cs" %>

Binding RadGrid for ASP.NET AJAX to ADO.NET Data Service

The second RadGrid from the online example referenced above is bound to ADO.NET Data Service. You need to point an existing ADO.NET data service to generate the grid content and specify the following settings:

ASP.NET
<ClientSettings>
    <DataBinding Location="GridAdoNetDataService.svc" SelectCountMethod="GetCount">
   	    <DataService TableName="Products" />
    </DataBinding>
</ClientSettings>

and GetCount method:

C#
[WebGet]
public int GetCount(string where)
{
    return String.IsNullOrEmpty(where) ? CurrentDataSource.Products.Count() : CurrentDataSource.Products.Where(where).Count();
}

The syntax of the ADO.NET Data Service class and the GridAdoNetDataService.svc file from the sample is presented in the forthcoming section:

ASP.NET

<%@ ServiceHost Language="C#" Factory="System.Data.Services.DataServiceHostFactory" Service="GridAdoNetDataService" %>
ASP.NET
using System;
using System.Data.Services;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel.Web;
using EntityFramework;
public class GridAdoNetDataService : DataService<NorthwindEntities>
{    
   public static void InitializeService(IDataServiceConfiguration config)
   {        
        config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
        config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
   }
   [WebGet]
   public int GetCount(string where)
   {
       return String.IsNullOrEmpty(where) ? CurrentDataSource.Products.Count() :
           CurrentDataSource.Products.Where(where).Count();
   }
}