响应式 WCF 客户端的双工回调或客户端线程

发布于 2024-07-11 19:36:22 字数 261 浏览 5 评论 0原文

我有一个特定的服务,其中特定的函数比其他函数调用需要更长的时间,有时它们可​​能需要几秒钟的时间才能返回。 为了防止发生这种情况时客户端的 UI 被阻塞,首选解决方案是:

  1. 使用双工通道并在收到数据时简单地使用回调来更新 UI。
  2. 使用单独的线程来调用服务,并且简单地使用请求-回复操作,然后在返回数据时更新ui线程。

哪种解决方案更好,特别是当互操作性受到青睐但并非绝对必要时,您认为哪种解决方案实施和维护更快(更干净)?

I have a certain service where specific functions will take longer to call than others, sometimes they might take seconds to return. In order to prevent the client's UI being blocked when this happens what is the preferred solution:

  1. Use a Duplex channel and simply use the callbacks to update the UI when data is received.
  2. Use a separate thread to call the service, and simply use request-reply operations, and then update the ui thread when data is returned.

Which solution is better, particularly when interoperability is favored but not strictly necessary, and in your opinion, which one is faster (and cleaner) to implement and maintain?

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

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

发布评论

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

评论(2

宁愿没拥抱 2024-07-18 19:36:22

如果您实现回调契约,那么您就不再需要客户端实现多线程代码。 在使用 .Net 客户端时,这可能不是一个显着的优势(因为 VS 会自动为您生成异步代理代码),但在与其他平台/语言的客户端一起使用时可能会证明是有益的。

哪一个更干净? 嗯,这取决于您是客户端开发人员还是服务器开发人员。 如果,正如我在您的情况下怀疑的那样,您两者都是,并且您可以只使用 .Net 作为客户端和服务器,那么我现在可能会想避免回调。 如果您暗示服务调用需要 45 秒,那么我会说回调合同,这确实是主观的,但如果我要坚持下去,那么我会说如果响应时间超过 5 秒那么是时候转向回调了。

If you implement callback contracts then you are removing the need for the client to implement multithreading code. This might not be a significant advantage when working with .Net clients (as VS will auto generate the asynch proxy code for you), though could prove beneficial when working with clients of other platforms/languages.

Which one is cleaner? Well, that depends whether you are a client or server developer. If, as I suspect in your case, you are both, and you can just use .Net for client and server, then I'd probably be tempted to avoid callbacks for now. If you'd have implied that the service calls where taking 45 seconds then I'd say call back contracts, it really is subjective, but if I were to stick my neck out then I'd say that if responses take longer than 5 seconds then it is time to move to callbacks.

a√萤火虫的光℡ 2024-07-18 19:36:22

您应该实现 CallBackcontract

这是一个示例

You should implement a CallBackcontract.

Here is an example.

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