Silverlight/C# - 动态加载 WCF 数据的最佳方法?

发布于 2024-11-29 06:06:54 字数 320 浏览 0 评论 0原文

我希望能够在 Silverlight 可用时将数据加载到 DataGrid 中。以下是场景:

  1. 我的 silverlight 客户端向服务器发起 WCF 调用。
  2. 服务器大约需要 1 到 2 秒的时间来响应。
  3. 响应在 1 MB 到 4 MB 之间(相当大)。
  4. 该数据被加载到 DataGrid 中。
  5. 尽管服务器响应速度很快,但直到 1 MB 到 4 MB 全部下载完毕后,用户才能看到数据。

当客户端下载这些数据时,将数据加载到 DataGrid 中的最佳(或最有效)方法是什么?而不是等待下载完成?

I would like 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清泪尽 2024-12-06 06:06:54

解决这个问题的一种方法是实施自定义虚拟化。

  • 添加仅返回 ids 的 Web 服务方法
  • 添加按 id 返回单个对象的 Web 服务方法

检索 ids 并仅加载可见对象(可能还需要加载更多对象以允许滚动)
需要滚动时检索更多对象。

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.

长发绾君心 2024-12-06 06:06:54

这个问题是我试图通过我的评论来解决的问题(您仍然没有真正指定返回的数据类型),以及 Erno 为您提供了可行的解决方案。 Web 服务会序列化您发送的任何返回类型,并且不会为您提供部分结果。这不是如何与网格交互的问题,而是客户端上的 Web 服务调用何时表示“好的,我收到了您需要的数据,现在继续处理”的问题。例如,如果您在服务器端收集一个包含 4MB 记录的数据表,那么在您的服务中执行以下操作:

return MyMassiveDatatable;

然后您将不得不等待整个数据表被序列化并通过网络传输。

他的解决方案是将传输分解为原子单元。 IE 首先在一个 Web 服务调用中查询记录的 id,然后迭代这些 id 并一次请求每个 id 的记录,当您收到返回的一条记录时,将其添加到客户端表中,以便您的显示器会在您收到每条记录时写入该记录。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文