Life is good. Compile & deploy!!!!
Over the past few weeks I have been developing a WCF Data Service. We hope to eventually allow for the service to be available to a lot of developers / users outside our control. We have some rather large tables in the service to call against and initially I had set the SetEntitySetPageSize setting to allow server side paging.
Great until someone asks for everything. No problem, just set the MaxResultsPerCollection also.
config.MaxResultsPerCollection = 100;
Wait… What’s this?
Hopefully, you’ve already setup your service for debugging.
Specification of entity set page size is mutually exclusive with the specification of MaxResultsPerCollection property in configuration.
Hmmm… Didn’t see that coming.
You can’t use these two options together. It’s one or the other. Pick your poison.
I’m using the March 2011 CTP2 WCF Data Service (latest release at this time). I’m hoping a future release will allow this. Seems rather logical to me that we might want to stop someone grabbing 70K rows by accident.
Sure we could handle some of this in the interface we provide to our users but what do you do when a user just does something like this:
ctx = new ServiceName(new Uri("servicelocation"));
DataServiceCollection<ODataExposedTable> exampleCollection= new DataServiceCollection<ODataExposedTable>();
exampleCollection.LoadCompleted += new EventHandler<LoadCompletedEventArgs>(exampleCollection_LoadCompleted);
var query = ctx.ODataExposedTable; //oh boy.... getting everything....
That’s a lot of waiting for 70K records to load….
Perhaps this is the point of an OData end point. Let the end user deal with it…?
Ask and ye shall receive
I posted this question on stack overflow as to why they don’t allow it and got a great response from an MS employee.
Both of these settings are a security/performance feature on the server. The MaxResultsPerCollection causes the server to fail the request if the limit is overrun. The SetEntitySetPageSize allows the server to return only a small part of the data, leaving it up to the client to ask for more if needs to do so. Other than really malicious clients who would bombard your server with many "get me next page" requests, the SetEntitySetPageSize is pretty much superior to the MaxResultsPerCollection. And there are easier ways to make your server suffer if it accepts unlimited number of requests for the client. As to your last question, I think that's actually a good thing that it's up to the client. Some clients might be able/want to handle all the data, no matter how large. Those who don't can stop at any time. Maybe if you could describe the scenario in which you think you would need both... –Vitek Karas
There you have it. Set the page size and move on. Don’t worry about the max results. By setting the page size you are already limiting how much your server gives out at once.