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;
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.