Web Service Timeout

amir100

Centurion
Joined
Mar 14, 2004
Location
Indonesia
I'm currently developing client windows applications accessing web services. I'm using VS.Net 2002. Now for the problems.

Timeout
It is to my understanding that sending synchronous web request will have a probability of experiencing time out. I'm creating an instance of my web service with the name "mywebservice". :D

Now I'm accessing a web service method; let's say Method1. When I'm executing mywebservice.Method1(), I get "The operation timed out" exception message.

An immediate solution to this problem was setting the timeout property of mywebservice to -1: mywebservice.Timeout = -1

Done. Too bad that solution doesn't last long enough. It leads to problem number two.

Underlying Connection was Closed
Yupe. It's a System.Net.WebException. The client cannot retrieve the response because the connection to the web server is closed. Closed? After reading a few references I discovered that it is due to the connection being timed-out but the client still thinks its open. What the ... @_@

Adding to the confusion is that the exception doesn't always occurred. Sometimes the code works perfectly fine without a single exception. What's with this behavior?

I'm kinda stuck here. I'd appreciate any help you have to offer.

But I've already set the time
 

amir100

Centurion
Joined
Mar 14, 2004
Location
Indonesia
Out of interest how long is it actually taking for the call to complete?

4 minutes in average.

Mind you that the exception only occured from time to time. It doesn't always throws the WebException I mentioned above. I've tested it in three different clients.

Thanks for the reply.
 

amir100

Centurion
Joined
Mar 14, 2004
Location
Indonesia
I've found the source of the problem. The problem lies within the "Connection Timeout" property of the Website. My testing server sets that property to 120 seconds. Which means I only got 2 minutes to send a request for a web service, execute the requested method, and retrieve the response from the web server. Since the average time of execution for the web methods is 4 minutes, the HTTP connection is closed by the server before the client retrieve the response. Hence I got the "Underlying Connection was Closed" WebException.

It looks like setting the Timeout property of each web service objects in the client to -1 isn't doing anything to prevent the web server from closing the HTTP connection.

I believe this has something to do with persistent connection and what-not. I've tried a few trick to disable persistent connection from the client side but it's not working. In the end the best fix was setting a higher "Connection Timeout" property in the IIS. I set it to 900 seconds (15 minutes).

Any comments? I was wondering what are the effects of increasing the "Connection Timeout" property. That and I'm still looking for a better solution. Anyone have a better idea?
 
Top Bottom