How to make a long polling client in C #?

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

Now I want to use long polling methods, but I can’t figure out how to do this from a client’s point of view.

How to set a timeout? Should I use a thread dedicated to this? Is there an example for a C # desktop application? (not found)

Thanks Dam

+3
source share
2 answers

You should be able to set a timeout in the web service object - the details will depend on which class it uses, but see WebClientProtocol.Timeout for an example.

Now you can either call it synchronously from a dedicated thread, or start an asynchronous call to the web service by specifying the callback that should be executed (possibly in the thread pool thread) when the service is responding. In this case, you may find that you can specify a timeout for an asynchronous call - again, this will depend on what proxy class you have for the web service.

This way, you don’t need to "waste" the thread just waiting for an answer - but you may find that an asynchronous programming model is harder to understand than a synchronous one. If you have only one or two of these requests at any given time, an extra pair of threads is unlikely to be a problem. If you expect responses from 500 different services, then, of course, there will be a different topic and an asynchronous model.

+4
source

For threading issues, see John's answer.

For the timeout task, here is the solution: In vs 2008, when I add the "service link" from wsdl, it will use WCF by default, and I cannot find how to set the timeout value with it.

So, when I right-click on links to services, I need to select "web links" (extended / added web link). Thus, it will use only “regular” web services and the Timeout parameter is available.

+1
source

Source: https://habr.com/ru/post/1388348/


All Articles