How to do a long polling client in C#?

不想你离开。 提交于 2019-11-30 23:30:33

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.

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.

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.

Dam's

For threading issues, see Jon's answer.

For the timeout problem, here's the solution: In vs 2008, when I add a "service reference" from a wsdl, it will use WCF by default, and I can't find how to set a timeout value with it.

So, when right clicking on Service References, I have to choose "web references" (advanced / add web reference). That way, it will use only "normal" web services and the Timeout parameter is available.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!