Groups | Blog | Home
all groups > dotnet web services > november 2005 >

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



matt NO[at]SPAM mailinator.com
11/3/2005 10:38:13 AM
hello,

i am using a .NET 1.1 winform to perform webrequests via the
System.Net.WebClient class (not a webservice, actually). 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
geraldbauer NO[at]SPAM yahoo.com
11/3/2005 4:29:47 PM
The reference.cs file is created via Visual Studios when you add a web
reference to a project. This file is automatically generated for you
that handles the communication between your reference to a webservice
method which is based upon the WSDL (the contract of what the
webservice provides to the world). Hope this helps explain the
reference.cs file for you.
AddThis Social Bookmark Button