Question

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.

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top