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.

image

[more]

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.

image

 

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.

image

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:

image

[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults=true)]
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 =
            System.Data.Services.Common.DataServiceProtocolVersion.V2;
    }
}

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: , , ,

.NET | WCF

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

Welcome

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!