In my application, I want to return a collection of objects from a WCF Service (hosted as a Windows Service) to populate a DataGrid in a WPF application. The amount of objects in the collection ranges from one to several hundred depending on the method called.
I'm curious as what is the 'best' way to deal with returning large collections from a service.
These are the options I've seen suggested are:
- Increasing the max message size and returning all the objects in one go. This seems like a bad idea because there could possibly come a time when I need to return more than 2GB of data.
- Paginating the records and calling the method repeatedly until all objects have been retrieved. I've seen this one suggested for ASP.NET projects but I don't know how well it would work for desktop apps.
- Using a stream. To be honest, I don't understand how this works since it appears to be meant for transferring large single objects rather than many smaller ones.
- Doing something with the
yield
keyword, but this went over my head and I couldn't follow it. :-/
What would be the best way approach this task, and why?