Web Service Timeout

amir100

Well-known member
Joined
Mar 14, 2004
Messages
190
Location
Indonesia
Im currently developing client windows applications accessing web services. Im 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. Im creating an instance of my web service with the name "mywebservice". :D

Now Im accessing a web service method; lets say Method1. When Im 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 doesnt last long enough. It leads to problem number two.

Underlying Connection was Closed
Yupe. Its 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 doesnt always occurred. Sometimes the code works perfectly fine without a single exception. Whats with this behavior?

Im kinda stuck here. Id appreciate any help you have to offer.

But Ive already set the time
 
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 doesnt always throws the WebException I mentioned above. Ive tested it in three different clients.

Thanks for the reply.
 
Ive 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 isnt 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. Ive tried a few trick to disable persistent connection from the client side but its 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 Im still looking for a better solution. Anyone have a better idea?
 
Back
Top