how to handle big lists for operation return in SOA
I'm trying to follow SOA approach to implement some services. I'm using WCF and I wanted to know what's the best approach/practice to handle long lists in operations. For example, I have a list of users to return to the UI (desktop client, not Web). If I return every开发者_高级运维 single record the list could get too big to be transfered from the service to the client and many errors can occur (like exceeding message size, or connection drop).
Is there a well known way to handle this kind of scenario?
Thanks a lot Alex,
If you have some idea of how many you're going to send, you can just increase the message size limits in the client's app.config and then go nuts. But you shouldn't send 50MB of customer records to every client without a reason.
If the user can only browse some of them at a time, you could grab some of the records then grab more as the user scrolls through the list. Alternately you can ask the user for a search pattern (like the first couple of letters) and only grab those.
Does the client need all the data (but you believe a single message is to large) or does he need only part of the data?
If he doesn't need all the data, a better approach may be to supply the user with a service that is capable of filtering.
If the user needs all the data, then the "classic" solution would be to return all the data. However, this may be problematic when the client is a thin client like a web application.
If the service is supposed to be a generic services (suitable for other clients) I would wrap it with a custom service that allows getting small "chunks" of data in each call. If the service isn't generic, and is custom made for this client - I would change the basic service to allow chunking of data.
Generally - having services that are "session oriented" isn't a good approach, but client server interaction withing an application isn't a typical service, and it usually has a stronger coupling then between general service provider and service consumer.
Thanks to everybody for your feedback.
I think I need to page the results. The service is for general use. It's intended to be consumed by any application (as an API).
So the most appropriate approach should be to get the data by chunks/pages. I can read up to certain number of rows in my client app (WPF).
Alex.
精彩评论