WebClient error: The underlying connection was closed: an unexpected error occurred on a receive

M

matt

hello,

i am using a .NET 1.1 winform to perform webrequests via the
System.Net.WebClient class. It uploads values via a POST command & a
URL, then receives the html back. nothing too complicated there.

except, i am frequently getting the dreaded error:

The underlying connection was closed: an unexpected error occurred
on a receive

....which after some googling, appears to be a .NET bug w/ regards to
open connections actually being closed. this error is typically run
into while working w/ ASP.NET webservers and/or webservices.

i have found many articles instructing one to disable keep-alives, and
using HTTP version 1.0. doing so in this method from the "reference.cs"
seems common:

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

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

....however, i dont know what this "reference.cs" file is.

can anyone provide me w/ the following clues:

- how can i have my WebClient object use a custom WebRequest like the
above?
- can i somehow set the keepalive & http version via the
WebClient.Headers collection?
- is this bug perhaps fixed in .NET 2.0 ?


any help would be appreciated!


thanks,
matt
 
G

Guest

How to edit reference.cs:

In your Visual Studio console, in the Solution Explorer, highlight the
project node of your Windows App or ASP.NET application which contains your
web reference proxy class. Then click the icon in the toolbar which allows
you to see the hidden files (I think the button will say 'Show All Files')

Then, you'll be able to expand these nodes:
Web References >> [Proxy Class] >> Reference.map >> Reference.cs

If you are just experimenting, you can add the override code snippet
directly inside of this class file (Reference.cs). However, if you ever
re-generate your proxy class, you'll lose your changes. It's better to create
a sub-class in your project that inherits from the class contained in
Reference.cs, and add your snippet there.

Brian
 

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