DCSIMG
Using Paging in WCF Data Services - Gil Fink's Blog

Gil Fink's Blog

Fink about IT

News

Microsoft MVP

My Facebook Profile My Twitter Profile My Linkedin Profile

Locations of visitors to this page

Creative Commons License

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
© Copyright 2013 Gil Fink

Hebrew Articles

Index Pages

My OSS Projects

English Articles

Using Paging in WCF Data Services

Using Paging in WCF Data Services

One of the mechanismsUsing Paging in WCF Data Services
which were provided
in WCF Data Services
from the start was
client side paging.
In the new release of
WCF Data Services we also
get a server side paging and this will be addressed in this post.

WCF Data Services Client Side Paging

From the early days of WCF Data Services we could achieve paging
on the client side using the $top and $skip query parameters.
For example the following URI for a data service will bring the 11-20
courses which were requested:

The problem starts when you expose resources with a lot of items.
Lets say that we have 10000 courses in our course library. The following
URI will bring to the client all of them:

Running this request will decrease the amount of clients for the service
since it will take ages for the query to return. So what can we do?
use server side paging instead.

WCF Data Services Server Side Paging

So how can we limit our returning result set to the client? we can
use a new feature of WCF Data Services. In order to create a
server side paging behavior all we need to do is to configure the
service to return some portion of data. We will use the new method
of the DataServiceConfiguration class which is called
SetEntitySetPageSize for each entity set or for all of them at once
(using * ). The following code create server side paging for all the
entity sets exposed by the data service to return only 10 items
at once:

public class SchoolDataService : DataService<SchoolEntities>
{    
  public static void InitializeService(DataServiceConfiguration config)
  {
    config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
    config.SetEntitySetPageSize("*", 10);
    config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
  }
}

When I use the service now with a URI to retrieve all the courses I will
get only the first ten courses. Also as you can see in the figure we
get a link at the bottom that leads us the next ten results:
Server Side Paging

and the link itself is written as:

http://localhost:8322/SchoolDataService.svc/Courses?$skiptoken=4041

Summary

In the new release of WCF Data Services we get a new paging
feature which enable server side paging. Using this method
or combining it with client side paging extend the capabilities
of WCF Data Services. The use of the server side paging is very
easy – just configure the service. In the post I showed an example
of how you can achieve that behavior.

Comments

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# June 19, 2010 4:57 PM

Using Paging in WCF Data Services - Gil Fink on .Net said:

Pingback from  Using Paging in WCF Data Services - Gil Fink on .Net

# June 20, 2010 12:16 AM

Twitter Trackbacks for Using Paging in WCF Data Services - Gil Fink on .Net [microsoft.co.il] on Topsy.com said:

Pingback from  Twitter Trackbacks for                 Using Paging in WCF Data Services - Gil Fink on .Net         [microsoft.co.il]        on Topsy.com

# June 20, 2010 11:23 AM

How to develop a WCF service which calls another WCF service? | SEM?????? said:

Pingback from  How to develop a WCF service which calls another WCF service? | SEM??????

# June 21, 2010 9:18 AM

Scott Banwart's Blog » Blog Archive » Distributed Weekly 56 said:

Pingback from  Scott Banwart&#039;s Blog  &raquo; Blog Archive   &raquo; Distributed Weekly 56

# June 25, 2010 5:26 PM