views:

672

answers:

2

Hello,

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

+1  A: 

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.

Jon Skeet
Thank you for your reply.I've tried with WebClientProtocol.Timeout, but I don't know what to do with it. My code is basically:ServiceReference1.TestSOAPImplClient test = new ServiceReference1.TestSOAPImplClient(); label1.Text = test.helloworld();And there is no timeout property. I've tried to add it in the generated reference.cs with no results.I think there is a basic step missing somewhere :)(btw, the remote web service was made in Java)For the thread issue, I will only have 2 or 3 long polling requests max, so I'll go synchronous with threads for now.
Dam's
What class does TestSOAPImplClient derive from?
Jon Skeet
In reference.cs, I have: [System.Diagnostics.DebuggerStepThroughAttribute()] [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")] public partial class TestSOAPImplClient : System.ServiceModel.ClientBase<WS_Client_Test1.ServiceReference1.TestSOAPImpl>, WS_Client_Test1.ServiceReference1.TestSOAPImpl . TestSOAPImpl is an interface and derives from nothing. All of this was generated automatically, maybe it's not the best way to use web services... :)
Dam's
Hmm... I can't see any timeout there, no. Unfortunately I don't know much about WCF...
Jon Skeet
Ok, I'll try to restart the project without using WCF (in fact, I don't remember chosing WCF...)
Dam's
A: 

Ok, so I got it.

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.

That's it.

Thanks Jon for your help !

Dam's