Server side paging in WCF Data Service


In this article, I will show you, how we can achieve server side paging in WCF Data service?

Note: IF you are new to WCF Data Service, please read my other articles on WCF Data Service.

PPT on WCF Data Service

Introduction to WCF Data Service

Here, I am assuming that, you have basic understanding of WCF Data service. So I will start with the code in .svc file or service file.



If we see in above code, we are setting the access rule for all the entity in the model to allow only the read operation.

How to enable paging at server side?

To enable paging at server side, we need to set the page the entity page size and also we need to explicitly set the version of the protocol to V2.



We are telling here that return only one record for all the entities .


using System;

using System.Collections.Generic;

using System.Data.Services;

using System.Data.Services.Common;

using System.Linq;

using System.ServiceModel.Web;

using System.Web;

namespace PagingSample


public class WcfDataService1 : DataService<StudentDBEntities >


public static void InitializeService(DataServiceConfiguration config)


config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);

config.SetEntitySetPageSize("*", 1);

config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;




Now when, we run the service, we can see


When, we navigate to Students table, we get the above result.


If , we notice above result , we can see , a link that will be used to navigate to next records.


How to fetch paged data at client side?

If we fetch the data at the client side in normal way as below,


Output, you will get name of only first student, because page size at server side is set to 1 .


So, if we want to get all the record through paging, we need to use Continuation property of DataServiceCollection.


So, above code will load the DataServiceCollection with all the data from the service. And then we can use normal foreach statement to print all the records


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Data.Services.Client;

using ConsoleApplication1.ServiceReference1;

namespace ConsoleApplication1


class Program


static void Main(string[] args)


StudentDBEntities ent = new StudentDBEntities(new Uri("http://localhost:11518/WcfDataService1.svc/"));

DataServiceCollection<Student> students = new DataServiceCollection<Student>(ent.Students);

while (students.Continuation != null)




foreach (var r in students)








When you run output would be as below,


So, this was all about how to enable server side paging in WCF Data Service. Thanks for reading. I hope article was useful. Happy Coding.

3 thoughts on “Server side paging in WCF Data Service

  1. Can we see an example of how to deploy WCF Data Services to a shared hosting site. Not just using the localhost? This would be of great help.

    Thank you.

  2. Yes, I would really like to see how to host a WCF Data Service on a web server as well.

    Thanks for all the great videos.

  3. Yes, I also would like to know the way to host the WCF data service.

    Thanks for all your efforts.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s