Solved

Getting "underlying connection was closed..." error on HttpWebRequest()

Posted on 2009-05-08
2
747 Views
Last Modified: 2013-12-17
We have a console application using HttpWebRequest on Win Server with .net 3.5. Intermittently, we get errors :

  The underlying connection was closed: An unexpected error occurred on a send. 

How can we correct this ?

Any advantage in adding ServicePointManager.MaxServicePoints and ServicePointManager.MaxServicePointIdleTime ?

Where would these be set  ?

Thank you,
Gary Davis
 
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(&.);
webReq.Method = "POST";
webReq.ContentType = "text/xml";
webReq.Headers.Add("Authorization", "Basic " + strAccount);
webReq.AuthenticationLevel = System.Net.Security.AuthenticationLevel.None;
webReq.KeepAlive = false;
 
HttpWebResponse webResp = (HttpWebResponse)webReq.GetResponse();
 
Stream stream = webResp.GetResponseStream() as Stream;
byte[] buffer = new byte[32 * 1024];
int nRead = 0;
MemoryStream ms = new MemoryStream();
 
do
{
 nRead = stream.Read(buffer, 0, buffer.Length);
 ms.Write(buffer, 0, nRead);
} while (nRead > 0);

Open in new window

0
Comment
Question by:Gary Davis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
Muhammad Ousama Ghazali earned 500 total points
ID: 24348255
The problem you are facing has been officially documented by Microsoft here: http://support.microsoft.com/default.aspx?scid=kb;EN-US;915599

For additional support, you may see this link too: http://weblogs.asp.net/jan/archive/2004/01/28/63771.aspx
0
 
LVL 18

Author Comment

by:Gary Davis
ID: 24400216
I have reviewed the sources and I am still seeing occasional issues so will try some different possibilities. I am closing this in any case.
Thanks
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
IDE for Python 5 73
TFS 2015 Access denied. 1 30
Multi-Column Repeater 3 29
Convert VB web project to C# 3 40
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question