ADO.NET (WCF) Data Services Paging – Where is SetEntitySetPageSize Method?

by James Richards April 01, 2010

When creating an ADO.NET or WCF Data Service, you can set up server based paging of the data by calling the SetEntitySetPageSize method on the config object as documented here and discussed in Scott Hanselman’s recent post on OData.

But after adding a new service to my project I tried to do this and the SetEntitySetPageSize method did not show up in Intellisense.



It turns out that when you create a new service the auto-generated code for the InitializeService method takes an IDataServiceConfiguration interface parameter, but the SetEntitySetPageSize method is defined on the DataServiceConfiguration class. So remove the “I” from the parameter type and try again.



Try something like config.SetEntitySetPageSize(“*”, 25) to set the page size to 25 entities per request for all entity types.

But there is still a problem. If you compile the project now and run a query against the service you will get the generic error message “The server encountered an error processing the request. See server logs for more details.”

To see a more detailed error message, add the [System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults=true)] attribute to the class and a config.UseVerboseErrors = true line to the InitializeService method.


Now when I run the query again I can see the cause of the problem: “Server paging cannot be used when the MaxProtocolVersion of the data service is set to DataServiceProtocolVersion.V1.”

To solve this we need to set the config.DataServiceBehavior.MaxProtocolVersion to V2, also shown in Scott’s post.

And now I have the Server Data Paging working! Here is the final version of the InitializeService method:


public class AdventureWorksService : DataService<AdventureWorksEntities>
    // This method is called only once to initialize service-wide policies.
    public static void InitializeService(DataServiceConfiguration config)
        config.UseVerboseErrors = true;
        config.SetEntitySetAccessRule("*", EntitySetRights.All);
        config.SetEntitySetPageSize("*", 25);
        config.DataServiceBehavior.MaxProtocolVersion =

I hope this helps someone who’s encountering the same problem.

Special thanks to Phani Raju for answering my question about this on the WCF Data Services MSDN Forum.

Additional References

Tags: , , ,


How To Use URL Rewriting for Extensionless WCF Svc Services with Helicon Tech ISAPI Rewrite

by James Richards February 02, 2009

Recently I was working on a WCF Service and wanted to serve it up with extensionless URLs. I downloaded and installed ISAPI Rewrite (Lite version) but struggled to come up with the correct regex expression to get it working.

I found many good blog postings and clues from Scott Gu, Scott Hanselman, and Jeff Atwood, and a thread on Stack Overflow, but none of these answered this specific question. As Scott Hanselman noted, URL rewriting can seem like "freaking voodoo".

So I moseyed on over to the Helicon Tech support forum and [more] asked the question. Anton (who I assume is one of the good folks at Helicon Tech) swiftly and correctly answered the question with the following example:

RewriteBase /
RewriteRule ^MyProject/MyService/products(.*)?$ MyProject/MyService.svc/products$1 [NC,L]

You can follow the complete thread here.

I hope this helps!

Tags: , , , , ,

.NET | ASP.NET | How To | REST | WCF

Powered by BlogEngine.NET
Theme by Mads Kristensen | Modified by Mooglegiant
Creative Commons License This work is licensed under a Creative Commons Attribution 3.0 United States License.


James Richards

Hi, I'm James Richards the CTO and co-founder of Artisan Global LLC. We make location-aware mobile apps with maps. I'm the author of QuakeFeed and I helped launch Zaarly at LASW Feb 2011. I also enjoy surfing, snowboarding, golfing, yoga, and music. I love my family: Linda, Sequoya and our cats Remy and Twiggy. Thanks for stopping by, I hope you find something helpful here.

Subscribe by RSS   Follow me on Twitter   Connect on Facebook   View my profile on LinkedIn

Amazon Associates

Some of my posts may contain Amazon Associates links. I only include these links when it makes sense within the context of the article. If you are in the market for one of these items, please consider clicking on an affiliate link to make your purchase. You still get the same great deal from Amazon and it will help me pay for hosting and bandwidth. Thanks!