Denis Pitcher

Denis Pitcher's Tech Blog
posts - 17, comments - 50, trackbacks - 30

My Links

News

Archives

System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

I've been trying to figure out what the cause of this problem is for a few days now and I've finally tracked down the error.

It's due to a bug in .net that closes the connection prior to it being finished.  I'm concerned about the performance issues involved in reconnecting, however I have written my code to keep most connections and data transfer small anyways, I'll have to keep an eye on the performance of this crappy bug.

A good reference for solving this issue is available at: http://p2p.wrox.com/topic.asp?TOPIC_ID=4858

Unfortunately the microsoft KB article that addressed the issue is no longer available.

As suggested I have added the following code to my reference.cs file (which needs to be done each time I update the webservice reference) to assign the keepalive value to false to allow the connection to be closed and reopened.

protected override WebRequest GetWebRequest(Uri uri)
        {
            HttpWebRequest webRequest = (HttpWebRequest) base.GetWebRequest(uri);

            webRequest.KeepAlive = false;
            webRequest.ProtocolVersion=HttpVersion.Version10;
            return webRequest;
        }

I have also added a reference to System.Net via a using statement to import the HttpWebRequest namespace.


Print | posted on Tuesday, August 16, 2005 2:31 PM |

Feedback

Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

I have encountered this issue in our web application as well and we are currently testing this solution for improved stability. In similar posts I have seen a discrepancy between the code snippets: some indicate the need to specify HTTP version 1.0, others omit that statement. Is it necessary? Does the solution not work if we leave the default of HTTP 1.1?
9/11/2005 12:31 PM | Ben Harper
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

From the research I've done, the issue is related to a bug in .Net that causes connections to be lost during a .net webservice call.

Essentially requests are made by opening a connection, making a number of them then closing it. In this occurance, the connection times out but is not recognized as closed and thus a new connection is not established for the next request and an error is returned.

Setting the keepalive to false sets it to close and reopen connections for each request. This taxes the server quite a bit more (some 7 connections for each new request). I would welcome any solutions to this error that don't involve this much traffic but I have yet to find any and am reluctant to write around it.

The suggestions I found indicated that setting the keepalive should solve it, yet some suggested setting the http version to 1.0.

There are variations in how the 1.0 and 1.1 versions of how the protocol work. Officially, the version 1.0 doesn't support keep-alives, however some implementations do support it.

.Net is designed to use http 1.1 to make requests which encourages persistant connections. It is more likely you'll avoid the error by forcing the use of the 1.0 protocol as it didn't take advantage of persistant connections (multiple requests per connection), however I cannot say either way as to whether the error won't still occur with the version set as 1.1

For example, leaving it set to use the 1.1 protocol will likely not try to keep the connection alive, but may still try to send more requests per connection which may cause the error to happen, just less frequently.

Unfortunately I cannot track down the original microsoft documentation on this issue as it seems to have disappeared, so outside of studying the documented http 1.0 and 1.1 versions of the protocol, comparing them and studying the .net implementation, there isn't much you can do aside from setting both to avoid the error.


9/13/2005 12:10 AM | Denis Pitcher
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

Thanks for the great article. We have also been experiencing the same error on our server. We have multiple web sites hosted in IIS on a 2003 server.

Our clients, specially a selected few, initially received the error with great frequency. But after a bit of research, we decided to turn off KeepAlives on all web sites right on the server. That made a tremendous difference. We are, however, still getting the same error with much lower frequency.

So we are now contemplating whether your proposed solution will make any difference, as the KeepAlives are already off in IIS. Unless we assume the HTTP version downgrade may be of some help.
9/15/2005 8:35 PM | BobbyA
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

Dennis,
You're awesome! I've been beating my head on this one for a while. Thank you for contributing this great info!

(good) Karma.upload(pitcher.dennis);
9/24/2005 1:09 AM | CJ
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

How does this "fix" affect webservice calls using threading? I have a .net windows app that uploads binary data (files) in separate threads.
10/3/2005 12:47 PM | Justin Rekas
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

Justin,

Thats a good question that I am unsure of the answer. Of the threaded webservice I've written, I didn't encounter this issue because I was interacting with a propriatary webservice.

I would assume threading would simply dictate more calls to be made as better use of IO and connections would likely occur. This may reduce the likelyhood of this error occuring but would not stop the error.

Seeing as this error is tied to the connection being kept alive. If the connection is believed to be alive but is actually terminated (as in this bug), I believe you would still encounter the same error, threaded or not.

I would welcome some feedback on this as I havn't explored the issue much in regards to threads.
10/3/2005 1:05 PM | Denis Pitcher
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

try:

HttpWebRequest webRequest = (HttpWebRequest)base.GetWebRequest(uri);

Thread.Sleep(1 * 1000);

...
11/10/2005 4:13 PM | KaosOverride
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

I do have the same problem under a load-balanced environment.

We are using 2 F5 Big-Ip.

11/17/2005 6:26 PM | Max
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

I had this same issue in a windows application I wrote. The application polls remote IIS Servers on a regular cyclic basis hosting an ASP page which packages up data and delivers it to the app for download. The application must use NT Authentication to auth with the ASP page and then performs an HTTP post followed by a download over SSL. The application sits on a windows 2000 server in the live environment and I used to see this error intermittently, but usually after the first few successful download cycles.

I tried the work around involving disabling keep-alives but this prevented NT Authentication from working so clearly wasn't an option. However after some testing I have managed to eradicate the fault by uninstalling .Net framework 1.1 and leaving only .Net framework version 2. The issue I am left with is on my development machine which requires .Net framework 1.1 to run VB.Net 2003. This also isn't an ideal solution since future upgrades/OS rebuilds when I have left the company must ensure .Net Framework ONLY is installed. That said after successfully running this without one error in just under a month ... it makes my head feel a whole lot better now the bruises from the table have cleared up!

Hope this helps anyway guys and if anyone else spies a more reliable, permanent fix short of upgrading to Visual Studio 2005 I'd be very grateful to hear of it!

Dave
1/4/2006 8:32 PM | Dave
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

None of the above solutions worked for me, but I found a solution for my problem and thought I'd share this in case it's applicable to someone else. I'm querying the SharePoint lists web-service Lists.asmx and got this nasty, vague exception. After hours of searching and fidling with IIS settings and .NET framework service packs to no avail, I finally realized Exception.InnerException != null, and behold there was another exception! It turns out setting the Timeout propery to 0 is invalid (I have a book that claims 0 means infinite - WRONG). You have to set Timeout to System.Threading.Timeout.Infinite, which has a constant value of -1. So the moral of the story: if you get vague exceptions and the solutions online don't work, check to see if your Exception contains an InnerException!
1/12/2006 5:32 PM | Jeff
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

I am getting the same error but in my case it seems to follow a pattern. The first time I make a call I get this error. If I try it the second time though, the call goes through. Is this the same issue, I mean the Keep Alive being set to true by default?
2/7/2006 6:57 PM | Aditya
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

I am using .net remoting to call an ejb using Ja.Net interoperability tool and i am using HTTP over SOAP channel. I get the same error message when i try to create a JNDI context.
How can i apply the "KeepAlive" in this case ?

My remoting client code is as follows :

RemotingConfiguration.Configure(@"D:\Sample\J-Integra\XMLDataTransfer\remoting_tcp.config");
Client client = new Client();
JNDIContext context = new JNDIContext();
client.home = (EchoHome)context.Lookup(HOME,JNDI);
client.remote = client.home.create();
6/9/2006 4:59 AM | Gurudath S Gaddad
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

Please see the knowledge base article recently published here: http://support.microsoft.com/default.aspx?scid=kb;EN-US;915599

This covers many known resolutions to the underlying connection closed exceptions
6/15/2006 9:26 PM | Mike Flasko
Gravatar

# Cool in .NET 2.0: HttpListener

For the past week, I've been busily converting a .NET 1.1/VS 2003 solution with about 350,000 lines of...
7/31/2006 12:38 PM | Matt's Weblog
Gravatar

# Worked like a charm

I was getting a the following exception when the System.Net.HttpWebResponse.GetResponse method was invoked (.NET 2.0; worked perfect in .NET 1.1):

"The underlying connection was closed A connection that was expected to be kept alive was closed by the server"

The exception was sporatic. For some odd reasons, it only failed every other time.

Setting the KeepAlive and ProtocolVersion properties of the HttpWebRequest instance solved the issue.

System.Net.HttpWebRequest httpRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(requestUri.ToString());

httpRequest.KeepAlive = false;
httpRequest.ProtocolVersion = HttpVersion.Version10;
8/24/2006 12:30 PM | Douglas Leung
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

Can someone please post a VB.NET version to the above solution?
10/16/2006 9:57 AM | yaron
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

Imports System.Net


Protected Overrides Function GetWebRequest(ByVal uri As Uri) As WebRequest
Dim webRequest As HttpWebRequest = CType(MyBase.GetWebRequest(uri), HttpWebRequest)
webRequest.KeepAlive = False
webRequest.ProtocolVersion = HttpVersion.Version10
Return webRequest
End Function
10/17/2006 6:06 PM | Anon Programmer
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

Hi All,

This is bug in IIS 6.0. To resolve this issue just install windows service pack 1 on thewindows 2003 server
12/22/2006 7:11 PM | Vijay Kumar
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

I am running my web services on Winodws Server 2003 w/ Service Pack 1 and have the same issue. Oddly I have only one user with this issue. When he runs the client on his home network (Hughes) he has the problem, on any other network he does not have a problem. This does not indicate to me that it is a bug in IIS, but I am still stumped.
2/8/2007 7:11 PM | plclogic
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

Hi!
I had the same problem with only one client... The problem was a misconfiguration of the IE proxy settings... We fixed it and voila!! all running ok now... Wish this helps you...

Regards,

Daniel
2/9/2007 5:59 PM | Daniel Vanzo
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

We're seeing this extremely rare bug on a few customers' machines. I've tried KeepAlive=false with no luck. Now we'll try HTTP1.0 as well to see if that makes any difference....
Thanks for the helpful page.
3/20/2007 9:54 PM | Taytay
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

I had this problem. Here's my fix:

webRequest.UsePassive = false

3/28/2007 6:00 PM | Mitch Lake
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

I have this problem only if the previous call to the web service has a time out.

Overriding WebRequest GetWebRequest(Uri uri) does not solve my problem.

Any idea?
Thanks, regards Andrea
4/13/2007 3:37 PM | andrea manara
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

HI,

For me it was the proxy, I disabled it totaly and everything
works!!

thanks a lot
5/8/2007 4:28 PM | David
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

I was having the exact problem listed here.

Reapplying windows server 2003 service pack 1 fixed the issue for me. Even though the service pack already existed on the machine
6/11/2007 10:30 AM | Mitch
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

Upgraded to new servers recently and have encountered this problem - causing our web application to crash.
Our network guys installed service pack 2 on this new server. Anyone else having a problem with sp2? I'm considering going back to sp1.
8/30/2007 2:07 PM | Joe
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

Thanks for the fix. I tried the KeepAlive = false fix and the error still does occur but after a lot more rows are processed. I can process 1619 rows before I encounter an error. This means that the as the number of connections to the server are made, it take longer and longer for the web service operation to complete because the server is under increasing load. It also has the unfortunate side-effect of filling up the database transaction log, requiring a manual flush.

Now I will try setting the proxy timeout to System.Threading.Timeout.Infinite and see if it can complete successfully.
9/18/2007 7:28 AM | Shailen Sukul
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

ok it broke again with the exception: The underlying connection was closed: An unexpected error occurred on a receive. --> System.IO.IOException Unable to read data from the transport connection ...

This time 1694 rows were processed before the error occurred.
9/18/2007 4:58 PM | Shailen Sukul
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

I noticed that this error ("The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.") started to appear after we migrated our codebase to 2.0. I tried the KeepAlive=false solution but that did not work on its own consistently. I found that if you assign a random unique value to the ConnectionGroupName property that it works like a charm. Here is my override...


protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
//throw new Exception("Custom WebRequest override code hit!!");
System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)base.GetWebRequest(uri);
webRequest.KeepAlive = false;
webRequest.ConnectionGroupName = Guid.NewGuid().ToString();
return webRequest;
}


Works like a charm! You can uncomment the exception throw to test that the override is in fact getting executed. Just paste this into the reference.cs and you're ready to go. Hope that helps...

9/26/2007 1:22 PM | Debbie
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

Can you please direct me where should i add the override funciton on the preference.cs file.

I tried open the file and dont know where to add those lines?

Thanks
E
11/5/2007 9:11 AM | eyal
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

Check that this is not caused by a recursive function loop

public void vSomeFunction(int i string s){

vSomeFunction(1,"Hello");

}

This can crash the application pool
12/3/2007 2:08 AM | VAInternet
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

MS KB Article (Resolution D):
http://support.microsoft.com/kb/915599/en-us

12/9/2007 1:07 AM | hB
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

I have developed a console based application that extracts data from xml. This code worked properly unitl last time i excuted the code for processing large number of xml files.

I am having the same error you guys discussing above but mine is console application. Did the tracing its throwing exceptinon while i try to load the XML. i.e

XmlDocument xdoc = new XmlDocument();
xdoc.Load(fs);


by the i am using NET 1.1 and VS 2003. Any suggestion for me?



2/6/2008 1:29 PM | Ahmedur Rab
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

FYI - I found a combination of suggestions worked. One issue was permission-based. I added ASPNET to Administrators and it reduced the errors almost completely. I have not yet whittled it down to a specific permission or group of permissions specifically.

I still got the error a few times, though, and I turned off KeepAlives and that did the trick. It is 100% gone now.
2/6/2008 10:17 PM | Mike
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

spoke too soon - started seeing it rarely. I instituted a recursive function that tried first with keepalives and http 1.1, then without keepalives and http 1.1, and finally without keepalives and http 1.0. seems to work. ugh.
2/6/2008 10:49 PM | Mike
Gravatar

# Try <httpRuntime maxRequestLength="1048576" />

I had the same problem. Non of the solutions worked for me. I Checked the error on server side in Global.asax. Then I realized I had to add
<httpRuntime maxRequestLength="1048576" />
to the web.config or the machine.config
Hope It works for you too
5/21/2008 12:27 AM | Amir Sharif
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

The issue we have is this: IIS apps on a DMZ server call a web service on the internal network to process logins. Whenever the machine hosting the webservice is rebooted, the IIS machine starts throwing this error. The only way to resolve it is to do IISReset on the DMZ machine. I have KeepAlives off and 1.0 enabled in the call to the web service from the DMZ code. Seems like it has to be a caching problem somewhere. I tried touching the web.config of the problem application but that didn't 'reset' it. I have added some of the suggestions above and will see if it has any effect. Namely:
System.Net.HttpWebRequest Req = (System.Net.HttpWebRequest)base.GetWebRequest(uri);
Req.Timeout = -1;
Req.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
Req.ConnectionGroupName = Guid.NewGuid().ToString();
Req.KeepAlive = false;
Req.ProtocolVersion = HttpVersion.Version10;
return (WebRequest)Req;

We'll see what happens. Thoughts?
5/23/2008 12:07 AM | Wade
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

Well, those changes didn't help. This time, when our DMZ server (Windows Server 2003 Std. SP 1) started throwing the error, I went to my dev server and fired up an app that calls the same web service. That machine could hit the service, no problem. So...I know the service is up and responding to requests. And I can manually hit the service from the DMZ by using a browser so I know the DMZ machine can actually get to it. It's just something inside of the IIS process(es) that is flaking out. I haven't upgraded the windows server to SP 2 yet. Maybe that would help. Does anyone think that the part of the error text 'an unexpected error ...on RECEIVE' is significant?
5/23/2008 11:18 PM | Wade
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

OK, more info. It apparently has nothing to do with the rebooting of the machine that has the service on it. The error occurrs just randomly. I patched Windows Svr 2003 up to SP 2. We'll see if that makes a difference. My next solution is to do a call to the web service w/o using the WebRequest object. If that fails, I may make an unmanaged call via COM to the dang thing!
5/24/2008 10:55 PM | Wade
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

So far, after patching to SP2, we have had no problems. It's only been about 3 days but that is still significant!
5/30/2008 12:13 PM | Wade
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

i created one console aplication -(,net 2.0)for uploading file from my local system to one ftp site -(,net 2.0)
for this i am using the ftp web request(file uploader concept)
i am getting the same error --
System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.
--
can any body help me
6/30/2008 10:12 AM | nob
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

I found out that the SP2 patch to our server never happened so it could be that for me. I doubt it, though. I suspect that it is just a pure bug in IIS whereby an http connection is trying to get re-used or something even though it shouldn't because after restarting IIS, it may run fine for a week or two.

Nob, have you tried using your same code to upload to a different site or does it fail for all of them?
7/1/2008 9:38 AM | Wade
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

I am calling a web service from a windows application.Everyting runs fine in my development and SIT server.But the same code bas throws the following error in my UAT server: "System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing"

The difference between SIT and UAT server is
1) UAT server is load balanaced but SIT is not
2) in SIT the web service is accessed by HTTP but in UAT it is accessed by HTTPS.

None of the resolution in this article has resolved my issue. Any help would be greatly appreciated.

Thanks in advance.Tanweer
7/29/2008 3:13 PM | Tanweer
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

my 2 cents:

req.Method = "Get" was causing the error for some of my sites, but not others. commented this line out solved my problem.
7/30/2008 7:22 AM | Johnny
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

We have this problem also.
It seems to only affect certain web services. Others work normally.

The only solution I have that works is to completely delete the entire database and then recreate a new database and repopulate. I make no changes to configuration or anything else. And then it magically works again.
So, possibly there is some connection to the database that is stuck open that is closed when the database is deleted.
10/9/2008 4:00 PM | Mark David
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

hi.
i want to try to set keepalive to false. but i m not sure if i could successfully set it or not.
i created a new class and in that class i override the GetWebRequest function. in the function body, i putted a line as follows:

throw new Exception("OKOK");

so i would understand if i set it or not. but that doesnt throw me OKOK exception message. does this mean that i couldnt override the function properly?
10/20/2008 6:37 AM | fer
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

None of the resolution fixed my issue..

here is my code:
//Initialisation
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(string.Format("{0}{1}", strPage, strVars));
//This time, our method is GET.
Thread.Sleep(1 * 1000);

WebReq.Method = "GET";
WebReq.Timeout = System.Threading.Timeout.Infinite;
WebReq.Credentials = CredentialCache.DefaultCredentials;
WebReq.ProtocolVersion = HttpVersion.Version10;
WebReq.KeepAlive = false;
WebReq.ConnectionGroupName = Guid.NewGuid().ToString();


//From here on, it's all the same as above.
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
//Let's show some information about the response
Console.WriteLine(WebResp.StatusCode);
Console.WriteLine(WebResp.Server);

//Now, we read the response (the string), and output it.
Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);
Console.WriteLine(_Answer.ReadToEnd());

This is a console application calling http://digg.com.. but no reply..I tried to call the some other site like microsoft.com.. it works for me.. but not for digg.com.. Any answers why?
11/18/2008 8:53 AM | Jag
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

To Daniel Vanzo:
I met this problem these days.And I found that
if Client's System Time is defferent from Server's System Time,a exception will be thrown.

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

Hope It works for you.
12/24/2008 4:52 AM | Junjie Yao
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

For me, I accessed the IE on the server on which IIS is being hosted. As per its security, it popped up whether to keep the url in its secure zone, i added it and tried to synchronise the wsus again and that was it.
3/4/2009 12:56 PM | Kwasi
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

Please, this is very urgent.
i have a mobile application that access to a web service.
some times it returns the error: (i don’t know what to do)


windows mobile system.net.webexception: unable to read data from the data transport system.net.socket exception: an existing connection was forcibly
6/17/2009 4:23 PM | Ricardo
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

I also had this issue and was able to solve it. The error is very misleading. Afer thaving solved this I do not think it is a defect with a specific version of .net or with timeouts etc etc.

I had one web service with only one method and i was receiving this error anytime i called the method from a windows client. Because I only had 1 method in my web service this was fairly easy for me to troubleshoot. As I started pulling code out of this method to eliminate the problem I began receiving errors in other areas of my webservice during testing (run time errors, not compile time errors). It turns out I had made a mistake in a class that was being called by my web service. I had a public property that called itself over and over again like so.

public string MyProperty
{
get{return MyProperty}
}

instead of

public string MyProperty
{
get{return _myProperty}
}


Because a compile time exception is not created with the code above the code compiles without issue. However this coding problem caused a stack overflow to occur in my web service every time i called it and that caused the error at the top of this page. The error was very misleading and was all caused by a defect in my code.

Hope this helps somebody.
9/1/2009 8:46 PM | Matt
Gravatar

# re: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.

I was facing the same issue( System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.). After lot of troubleshooting I found that the somehow the host file under C:\WINDOWS\system32\drivers\etc has changed and was containing wrong IP Address for my site. After I corrected it to point to right one it started working.

Hope this helps!!!
10/21/2009 4:43 AM | Pawan Gupta
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: