2006-03-24

Solving "The underlying connection was closed: An unexpected error occurred on a send." (Webservices)

Jan Thielen (MVP) gives a solution to the problem of sporadic errors of type "The underlying connection was closed".

In essence, you need to add the following code to your Webreference's Reference.cs file:


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

No comments:

Post a Comment