如何做到在C#长轮询客户端? [英] How to do a long polling client in C#?

查看:194
本文介绍了如何做到在C#长轮询客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#桌面应用程序,我使用Web服务没有问题(通过添加服务引用添加WSDL,所以我创建了一个对象,并调用它的函数)。

I have a C# desktop application, and I consume a web service without problems (wsdl added by "add Service References", so I create an object and call its functions).

现在,我要使用长轮询技术,但我想不出如何从客户端的角度做到这一点。

Now, I want to use long polling techniques but I can't figure how to do this from the client's perspective.

如何配置超时?
我应该使用专门为这一主题?
是否有一个C#桌面应用程序的例子吗? (没有发现任何)

How to configure the timeout ? Should I use a thread dedicated to this ? Is there any example for a C# desktop application ? (haven't found any)

谢谢,
大坝的

Thanks, Dam's

推荐答案

您应该能够配置Web服务对象的超时 - 细节将取决于究竟它使用的类,但看的 WebClientProtocol.Timeout 一个例子。

You should be able to configure the timeout on the web service object - the details will depend on exactly which class it's using, but look at WebClientProtocol.Timeout for an example.

现在,你既可以同步调用,从一个专门的线程,或者你可以做一个的异步的调用Web服务入手,指定回调执行(可能在一个线程池线程)当服务回复。在这种情况下,你会发现你可以在异步调用本身指定超时 - 再次,这将取决于到底是什么样的,你已经有了Web服务代理类的

Now you could either call that synchronously from a dedicated thread, or you could make an asynchronous call to the web service to start with, specifying a callback to be executed (probably on a thread pool thread) when the service replies. In that case, you may find you can specify the timeout on the asynchronous call itself - again, it will depend on exactly what kind of web service proxy class you've got.

这样,你不必浪费只是在等待响应的话题 - 但你可能会发现,异步编程模型是难度比同步个明白。如果你只有一个或两个这些请求在任何一个时间的,额外的情侣线程不太可能是一个问题。如果你正在等待来自500个不同的服务响应,这是一个不同的问题和异步模式肯定是要走的道路。

That way you don't need to "waste" a thread just waiting for the response - but you may find that the asynchronous programming model is harder to understand than the synchronous one. If you've only got one or two of these requests at any one time, the extra couple of threads is unlikely to be an issue. If you're waiting for responses from 500 different services, that's a different matter and the async model would definitely be the way to go.

这篇关于如何做到在C#长轮询客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆