Closed connection is being re-used


E

Eric

Hello,

I have a windows service (written on .NET 1.1/C#) connecting to a webservice
at a specified interval. I have a webreference in my project, create and
instance of this object, and call my webservice methods. The interval was
initially set to 60 seconds and everything was working fine. I changed the
config so that the service is connecting to the webservice every 5 minutes.
This is when i started getting the following error messages: 'The underlying
connection was closed: An unexpected error occurred on a send.'

I did some investigation on this error and used a packet sniffer to see what
is exactly happening. The first time everything is working fine and after
about 2 minutes the connection is reset. (Server sends TCP header with RST
flag). The instance of proxy class (from webreference) does not detect the
connection is reset and tries to connect over the closed connection. This
causes the exception. The next call will succeed (a new connection is
created), the following call will fail again etc. I thought that creating a
new instance of the proxy class at every call and explicitly call Dispose()
would fix my problem but it doesn't. There seems to be some connection
pooling not removing closed connections?

Any idea what causes this behaviour? Thanks in advance!

Eric
 
Ad

Advertisements

K

Keenan Newton

I think your problem is in the IIS configureation there is a default
timeout setting and i beleive it is set to 120 seconds. I am assuming
your web service call is taking longer then 2 minutes to process. Try
adjusting this settting it can be found in the properties window.
 
E

Eric

No that is not the problem. It's not a single webservice call that takes
more than 120 seconds. I do a call which is successful, wait 5 minutes, and
perform another call. This second call is done over the same connection as
the first call but this connection is no longer valid. I need to set up a
new connection but somehow the generated proxy class chooses the closed
connection causing the error.
 
Ad

Advertisements

E

Eric

I found a solution to my problem! Add this code to your generated proxy
class:

protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)
base.GetWebRequest(uri);
webRequest.KeepAlive = false;
return webRequest;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top