开发者

Silverlight/C# - Best way to dynamically load WCF data?

I would l开发者_StackOverflow社区ike to be able to load data into a DataGrid in Silverlight as it becomes available. Here is the scenario:

  1. My silverlight client fires a WCF call to the server.
  2. The server takes about 1 to 2 seconds to respond.
  3. The response is between 1 MB and 4 MB (quite large).
  4. This data is loaded into a DataGrid.
  5. Although the server responds quickly, the data is not seen by the user until all 1 MB to 4 MB has been downloaded.

What is the best (or most efficient) way to load this data into the DataGrid as it is being downloaded by the client? As opposed to waiting for the download to complete?


A way of handling this is implementing custom virtualization.

  • Add a webservice method that returns only ids
  • Add a webservice method that returns a single object by id

Retrieve the ids and load only the visible objects (and perhaps a few more to allow scrolling) Retrieve more objects when needed for scrolling.


The problem is part of what I was trying to get at with my comment (you still didn't really specify the Datatype for the return), and what Erno gave you a workable solution for. The web service serializes whatever return type you are sending, and will not give you partial results. It's not a question of how you interface with the grid, it's a question of when the web service call on the client says "ok i received the data you need, now continue processing". For instance, if you are gathering up a data table on the server side with 4MB worth of records, then in your service do a :

return MyMassiveDatatable;

Then you are going to have to wait for the entire data table to be serialized and pumped across the wire.

His solution was to break up the transfer into atomic units. I.E. query first for the id's of the records in one web service call, then iterate through those id's and request the record for each id one at a time, and as you receive the one record back, add that to your client side table so that your display writes each record as you get it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜