简体   繁体   English

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

[英]Duplex Callbacks or Client-Side Threading for Responsive WCF Clients

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: 为了防止在发生这种情况时阻止客户端的UI,首选解决方案是什么:

  1. Use a Duplex channel and simply use the callbacks to update the UI when data is received. 使用双工通道,只需使用回调即可在收到数据时更新UI。
  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. 使用单独的线程来调用服务,只需使用请求 - 回复操作,然后在返回数据时更新ui线程。

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? 哪种解决方案更好,特别是在互操作性受到青睐但不是绝对必要时,并且您认为哪种解决方案更快(更清洁)的实施和维护?

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. 在使用.Net客户端时,这可能不是一个显着的优势(因为VS将为您自动生成异步代理代码),但在与其他平台/语言的客户端合作时可能会有所帮助。

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. 如果,正如我怀疑你的情况,你是两个,并且你可以只使用.Net作为客户端和服务器,那么我现在可能想要避免回调。 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. 如果你暗示服务呼叫需要45秒,那么我会说回叫合同,这确实是主观的,但如果我要坚持下去,那么我会说如果响应时间超过5秒那么是时候转向回调了。

You should implement a CallBackcontract . 您应该实现CallBackcontract

Here is an example . 这是一个例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM