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

J

Joel Zhou

We are running IIS 6 on Win2003, with .Net 1.1. I have a client that
talks to my Web Service. The Web Service call is pretty lengthy (can
take more than a few minutes to complete).

I noticed when the web service call takes more than ~180 seconds to
complete, the client will get the above exception. I tried calling
both synchronously and asynchronously call and they both failed with
the same error.

If I increase the "Connection timeout" in the IIS Manager for the web
site, I can increase the time before the client will get the
exception. However, I don't expect the IIS to timeout my client
connection since the client is waiting for the server to complete the
call. I set the client side timeout to a huge number (int.MaxValue). I
tried WinXP with .Net 1.1 and I didn't have this error.

I tried Q819450 but it didn't help. I cannot turn off Keep-alives
because I use Integrated Windows Authentication.

Anyone know what might be the problem here?

Thanks,
Joel
 
G

Guest

We are running IIS 6 on Win2003, with .Net 1.1. I have a client that
talks to my Web Service. The Web Service call is pretty lengthy (can
take more than a few minutes to complete).

I noticed when the web service call takes more than ~180 seconds to
complete, the client will get the above exception. I tried calling
both synchronously and asynchronously call and they both failed with
the same error.

If I increase the "Connection timeout" in the IIS Manager for the web
site, I can increase the time before the client will get the
exception. However, I don't expect the IIS to timeout my client
connection since the client is waiting for the server to complete the
call. I set the client side timeout to a huge number (int.MaxValue). I
tried WinXP with .Net 1.1 and I didn't have this error.

I tried Q819450 but it didn't help. I cannot turn off Keep-alives
because I use Integrated Windows Authentication.

Anyone know what might be the problem here?

Thanks,
Joel

Hello,

You are describing exactly the same problem we have.
Our webservice takes also long time to finish. If we are running on WinXP with IIS 5.1, there is no problem, but on Windows2003 with IIS 6.0, the client gets an exception.
I tested with the 'turn-off keep-alives', but the problem was not resolved.

Did you find any solution?
Regards,
Eri

User submitted from AEWNET (http://www.aewnet.com/)
 
R

RK

We had this problem earlier, but the fix in microsoft kb819450 worked
for us.
In our case C# class library is making call to web service.. so we
created wrapper class and added the following code in it..

class classWebServiceWrapper:myWebService
{
protected override WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest webRequest =
(HttpWebRequest)base.GetWebRequest(uri);
webRequest.KeepAlive = false;
return webRequest;
}
}

so inside the class library instead calling web service directly, call
wrapper class as follows

myWebService ws = new classWebServiceWrapper();

ps:
protected override WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest webRequest =
(HttpWebRequest)base.GetWebRequest(uri);
webRequest.KeepAlive = false;
return webRequest;
}
Adding this code in reference.cs file is also worked for us. but
everytime adding this part of the code is little extra work, so we
were using wrapper class.


goodluck.
--RK
 
S

subha

Did you find any solution to this? I have a similar error - mine says
unexpected error occured on a send. I have windows 2000 and IIS 5.0 -
I have the HTTP- keep alives turned off. Did not help. I tried adding
the code block for keepalives false. That did not help either.
 
R

RK

what is the version of .NET Framework are you using?

http://support.microsoft.com/default.aspx?scid=kb;EN-US;819450
resolved my problem.

Leave Http-keep alives property CHECKED-ON on the server. Try adding
the following code in reference.cs file and then compile your client
application.

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

webRequest.KeepAlive = false;

return webRequest;
}

--RK
 
S

subha

I have both .NET 1.0 and 1.1 installed. My aspnet_isapi.dll is 1.1.4322.2035
I believe.
I have tried KB article and HTTP keep alive. I am connecting to the service
 
D

Dan Rogers

Hi,

I'm sure that I must be misunderstanding your question - which as I read
down thru the thread tells me that you know your web service logic is
taking a very long time, and that unless you turn up the server side
timeout threshold, the server timeout logic does what it is designed to do
- close the connection and kill the thread. The result in the client is a
timeout exception gets raised, and the caller is informed that the request
did not complete.

From what I can tell, this is what is supposed to be happening, and the
fact that you can set the timeout to a large enough value to accommodate
your call seems to also indicate that the server is working as designed.

To get an idea as to why this could possibly be "correct behavior" -
consider the role that the web server plays. It has a limited number of
threads that it has to share all work across. Each request is allocated to
a thread, and as long as a request is being serviced, the pool of available
threads is reduced by the number of active requests. In the case of long
response times due to making the server do a whole lot of work, the web
server by default will see this as a resource problem, conclude that the
thread has gone bonkers, and so it kills it.

To prevent the server from doing this, you get to choose how long too long
is on a per service basis.

Now for some unasked for advice: Don't make your services do these kind of
long long requests. The propensity for requesters to conclude the same
thing the server has concluded is normal - so what ends up happening is
people hit the refresh, or programs retry in these long long operation
scenarios. If the server didn't kill off wayward threads, this retry
behavior would quickly exhaust the capacity of resources on the server, and
the callers still don't have their answer.

If you need to make batch-like operations happen, make them happen by
letting the web service call kick off the work, and then immediately
return, not awaiting the end of the operation. If you need to let the
callers know when their particular "batch" has completed, you can have them
provide a parameter with a unique ID in it that specifies the batch number.
When you kick off the long running operation (perhaps using a job
scheduler), you can log the batch and relate it to the caller assigned ID.
Alternately you could return the batch ID to the caller.

Later, the caller can periodically poll to see if a particular batch is
done. In this way, the connection to the web server isn't kept open, the
thread on the server isn't kept busy for undue periods, and the caller
isn't hung waiting for your slow server side operation to complete.

I hope this helps,

Dan Rogers
Microsoft Corporation
--------------------
 
S

subha

Dan,
Joel's webservice call took a long time. Mine is a very small call. I just
print HelloWorld. On the IE browser, the method gets invoked and shows me the
result in a few seconds. But, my C# app throws this error about Underlying
connection.
 
D

Dan Rogers

Have you tried checking the ASP.net configuration for this vroot?

I see this sometimes - cant' say that it's doing the right thing. But I've
had success in going to the vroot in IIS manager, and if the Application
field is blank (but not greyed out), try clicking the "remove" button,
followed by the "create" button. This re-sets the application settings -
which may have become corrupt.

Hope that helps

Dan Rogers
Microsoft Corporation
--------------------
 
S

Sefai

If you need to make batch-like operations happen, make them happen by
Can you give an example for "kick off operation". I mean how to
continue operation after you return the WebMethod.

Thanks.
 
D

Dan Rogers

You could make your web method start a scheduled job (e.g. batch), or place
the message in a queue and have a service or a COM+ component do the work.

There are even ways to do an asynch server side execution. One of them is
to make the method a one-way method. The other is to add in Begin/End
method shells on the server side. See the article at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/h
tml/service10012002.asp.

Hope this helps

Dan Rogers
--------------------
From: (e-mail address removed) (Sefai)
Newsgroups: microsoft.public.dotnet.framework.aspnet.webservices
Subject: Re: The underlying connection was closed: An unexpected error occu
Date: 26 Nov 2004 01:28:27 -0800
Organization: http://groups.google.com
Lines: 27
Message-ID: <[email protected]>
References: <[email protected]>
<[email protected]>
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top