.NET Web Services Client "underlying connection was closed"

We have written an ASP.NET web service, and are using a .NET generated client proxy to access that service. We are getting intermittent errors of the following form:

"The underlying connection was closed: A connection that was expected to be kept alive was closed by the server."
--
Stack Trace:
at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at (our custom code)

We are using C# in .NET 2.0. Our server is Windows Server 2003; the client is on Windows XP.

Any help will be appreciated. Thanks; Michael

[797 byte] By [MichaelHogue] at [2007-12-26]
# 1

please get a system.net trace using the blog article
http://blogs.msdn.com/dgorti

DurgaprasadGorti at 2007-9-4 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 2

MichaelHogue at 2007-9-4 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 3

I have the trace. I'm pretty unclear what I'm looking at, but I'll post a fragment of it here. I basically looked for the error message in the log that was generated and copied the stuff above it and below it. (Forgive me; I don't really know forum etiquette... I couldn't find an "attach file" option on my reply, or I would have posted the whole file). The error that we get is "The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.", and that text can be seen in this log.

Thanks for any help that can be provided.

Michael

System.Net Information: 0 : [1784] HttpWebRequest#54708252 - Request: POST /TaxApp/TaxProductWSAPI.asmx HTTP/1.1

System.Net Information: 0 : [1784] ConnectStream#34257225 - Sending headers

{

User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.42)

Content-Type: text/xml; charset=utf-8

SOAPAction: "http://com.avenity.taxproduct/GetLastCacheRefresh"

Host: 172.16.11.22

Content-Length: 487

Expect: 100-continue

}.

System.Net Information: 0 : [1784] Connection#8022616 - Received status line: Version=1.1, StatusCode=100, StatusDescription=Continue.

System.Net Information: 0 : [1784] Connection#8022616 - Received headers

{

}.

System.Net Verbose: 0 : [1784] Data from ConnectStream#34257225::ResubmitWrite

System.Net Verbose: 0 : [1784] 00000000 : 3C 3F 78 6D 6C 20 76 65-72 73 69 6F 6E 3D 22 31 : <?xml version="1

System.Net Verbose: 0 : [1784] 00000010 : 2E 30 22 20 65 6E 63 6F-64 69 6E 67 3D 22 75 74 : .0" encoding="ut

System.Net Verbose: 0 : [1784] 00000020 : 66 2D 38 22 3F 3E 3C 73-6F 61 70 3A 45 6E 76 65 : f-8"?><soap:Enve

System.Net Verbose: 0 : [1784] 00000030 : 6C 6F 70 65 20 78 6D 6C-6E 73 3A 73 6F 61 70 3D : lope xmlns:soap=

System.Net Verbose: 0 : [1784] 00000040 : 22 68 74 74 70 3A 2F 2F-73 63 68 65 6D 61 73 2E : "http://schemas.

System.Net Verbose: 0 : [1784] 00000050 : 78 6D 6C 73 6F 61 70 2E-6F 72 67 2F 73 6F 61 70 : xmlsoap.org/soap

System.Net Verbose: 0 : [1784] 00000060 : 2F 65 6E 76 65 6C 6F 70-65 2F 22 20 78 6D 6C 6E : /envelope/" xmln

System.Net Verbose: 0 : [1784] 00000070 : 73 3A 78 73 69 3D 22 68-74 74 70 3A 2F 2F 77 77 : s:xsi="http://ww

System.Net Verbose: 0 : [1784] 00000080 : 77 2E 77 33 2E 6F 72 67-2F 32 30 30 31 2F 58 4D : w.w3.org/2001/XM

System.Net Verbose: 0 : [1784] 00000090 : 4C 53 63 68 65 6D 61 2D-69 6E 73 74 61 6E 63 65 : LSchema-instance

System.Net Verbose: 0 : [1784] 000000A0 : 22 20 78 6D 6C 6E 73 3A-78 73 64 3D 22 68 74 74 : " xmlns:xsd="htt

System.Net Verbose: 0 : [1784] 000000B0 : 70 3A 2F 2F 77 77 77 2E-77 33 2E 6F 72 67 2F 32 : p://www.w3.org/2

System.Net Verbose: 0 : [1784] 000000C0 : 30 30 31 2F 58 4D 4C 53-63 68 65 6D 61 22 3E 3C : 001/XMLSchema"><

System.Net Verbose: 0 : [1784] 000000D0 : 73 6F 61 70 3A 48 65 61-64 65 72 3E 3C 42 61 73 : soap:Header><Bas

System.Net Verbose: 0 : [1784] 000000E0 : 69 63 41 75 74 68 65 6E-74 69 63 61 74 69 6F 6E : icAuthentication

System.Net Verbose: 0 : [1784] 000000F0 : 48 65 61 64 65 72 20 78-6D 6C 6E 73 3D 22 68 74 : Header xmlns="ht

System.Net Verbose: 0 : [1784] 00000100 : 74 70 3A 2F 2F 63 6F 6D-2E 61 76 65 6E 69 74 79 : tp://com.avenity

System.Net Verbose: 0 : [1784] 00000110 : 2E 74 61 78 70 72 6F 64-75 63 74 2F 22 3E 3C 55 : .taxproduct/"><U

System.Net Verbose: 0 : [1784] 00000120 : 73 65 72 4E 61 6D 65 3E-4D 49 43 48 41 45 4C 3C : serName>MICHAEL<

System.Net Verbose: 0 : [1784] 00000130 : 2F 55 73 65 72 4E 61 6D-65 3E 3C 50 61 73 73 77 : /UserName><Passw

System.Net Verbose: 0 : [1784] 00000140 : 6F 72 64 3E 41 76 65 6E-69 74 79 3C 2F 50 61 73 : ord>Avenity</Pas

System.Net Verbose: 0 : [1784] 00000150 : 73 77 6F 72 64 3E 3C 2F-42 61 73 69 63 41 75 74 : sword></BasicAut

System.Net Verbose: 0 : [1784] 00000160 : 68 65 6E 74 69 63 61 74-69 6F 6E 48 65 61 64 65 : henticationHeade

System.Net Verbose: 0 : [1784] 00000170 : 72 3E 3C 2F 73 6F 61 70-3A 48 65 61 64 65 72 3E : r></soap:Header>

System.Net Verbose: 0 : [1784] 00000180 : 3C 73 6F 61 70 3A 42 6F-64 79 3E 3C 47 65 74 4C : <soap:Body><GetL

System.Net Verbose: 0 : [1784] 00000190 : 61 73 74 43 61 63 68 65-52 65 66 72 65 73 68 20 : astCacheRefresh

System.Net Verbose: 0 : [1784] 000001A0 : 78 6D 6C 6E 73 3D 22 68-74 74 70 3A 2F 2F 63 6F : xmlns="http://co

System.Net Verbose: 0 : [1784] 000001B0 : 6D 2E 61 76 65 6E 69 74-79 2E 74 61 78 70 72 6F : m.avenity.taxpro

System.Net Verbose: 0 : [1784] 000001C0 : 64 75 63 74 2F 22 20 2F-3E 3C 2F 73 6F 61 70 3A : duct/" /></soap:

System.Net Verbose: 0 : [1784] 000001D0 : 42 6F 64 79 3E 3C 2F 73-6F 61 70 3A 45 6E 76 65 : Body></soap:Enve

System.Net Verbose: 0 : [1784] 000001E0 : 6C 6F 70 65 3E 0D 0A : lope>..

System.Net Information: 0 : [1784] Connection#8022616 - Received status line: Version=1.1, StatusCode=200, StatusDescription=OK.

System.Net Information: 0 : [1784] Connection#8022616 - Received headers

{

Content-Length: 401

Cache-Control: private, max-age=0

Content-Type: text/xml; charset=utf-8

Date: Tue, 07 Nov 2006 08:21:56 GMT

Server: Microsoft-IIS/6.0

X-AspNet-Version: 2.0.50727

X-Powered-By: ASP.NET

}.

System.Net Information: 0 : [1784] ConnectStream#48313086::ConnectStream(Buffered 401 bytes.)

System.Net Information: 0 : [1784] Associating HttpWebRequest#54708252 with ConnectStream#48313086

System.Net Information: 0 : [1784] Associating HttpWebRequest#54708252 with HttpWebResponse#7941859

System.Net Verbose: 0 : [1784] Exiting HttpWebRequest#54708252::GetResponse() -> HttpWebResponse#7941859

System.Net Verbose: 0 : [1784] HttpWebResponse#7941859::GetResponseStream()

System.Net Information: 0 : [1784] ContentLength=401

System.Net Verbose: 0 : [1784] Exiting HttpWebResponse#7941859::GetResponseStream() -> ConnectStream#48313086

System.Net Verbose: 0 : [1784] ConnectStream#48313086::Read()

System.Net Verbose: 0 : [1784] Data from ConnectStream#48313086::Read

System.Net Verbose: 0 : [1784] 00000000 : 3C 3F 78 6D 6C 20 76 65-72 73 69 6F 6E 3D 22 31 : <?xml version="1

System.Net Verbose: 0 : [1784] 00000010 : 2E 30 22 20 65 6E 63 6F-64 69 6E 67 3D 22 75 74 : .0" encoding="ut

System.Net Verbose: 0 : [1784] 00000020 : 66 2D 38 22 3F 3E 3C 73-6F 61 70 3A 45 6E 76 65 : f-8"?><soap:Enve

System.Net Verbose: 0 : [1784] 00000030 : 6C 6F 70 65 20 78 6D 6C-6E 73 3A 73 6F 61 70 3D : lope xmlns:soap=

System.Net Verbose: 0 : [1784] 00000040 : 22 68 74 74 70 3A 2F 2F-73 63 68 65 6D 61 73 2E : "http://schemas.

System.Net Verbose: 0 : [1784] 00000050 : 78 6D 6C 73 6F 61 70 2E-6F 72 67 2F 73 6F 61 70 : xmlsoap.org/soap

System.Net Verbose: 0 : [1784] 00000060 : 2F 65 6E 76 65 6C 6F 70-65 2F 22 20 78 6D 6C 6E : /envelope/" xmln

System.Net Verbose: 0 : [1784] 00000070 : 73 3A 78 73 69 3D 22 68-74 74 70 3A 2F 2F 77 77 : s:xsi="http://ww

System.Net Verbose: 0 : [1784] 00000080 : 77 2E 77 33 2E 6F 72 67-2F 32 30 30 31 2F 58 4D : w.w3.org/2001/XM

System.Net Verbose: 0 : [1784] 00000090 : 4C 53 63 68 65 6D 61 2D-69 6E 73 74 61 6E 63 65 : LSchema-instance

System.Net Verbose: 0 : [1784] 000000A0 : 22 20 78 6D 6C 6E 73 3A-78 73 64 3D 22 68 74 74 : " xmlns:xsd="htt

System.Net Verbose: 0 : [1784] 000000B0 : 70 3A 2F 2F 77 77 77 2E-77 33 2E 6F 72 67 2F 32 : p://www.w3.org/2

System.Net Verbose: 0 : [1784] 000000C0 : 30 30 31 2F 58 4D 4C 53-63 68 65 6D 61 22 3E 3C : 001/XMLSchema"><

System.Net Verbose: 0 : [1784] 000000D0 : 73 6F 61 70 3A 42 6F 64-79 3E 3C 47 65 74 4C 61 : soap:Body><GetLa

System.Net Verbose: 0 : [1784] 000000E0 : 73 74 43 61 63 68 65 52-65 66 72 65 73 68 52 65 : stCacheRefreshRe

System.Net Verbose: 0 : [1784] 000000F0 : 73 70 6F 6E 73 65 20 78-6D 6C 6E 73 3D 22 68 74 : sponse xmlns="ht

System.Net Verbose: 0 : [1784] 00000100 : 74 70 3A 2F 2F 63 6F 6D-2E 61 76 65 6E 69 74 79 : tp://com.avenity

System.Net Verbose: 0 : [1784] 00000110 : 2E 74 61 78 70 72 6F 64-75 63 74 2F 22 3E 3C 47 : .taxproduct/"><G

System.Net Verbose: 0 : [1784] 00000120 : 65 74 4C 61 73 74 43 61-63 68 65 52 65 66 72 65 : etLastCacheRefre

System.Net Verbose: 0 : [1784] 00000130 : 73 68 52 65 73 75 6C 74-3E 2D 31 3C 2F 47 65 74 : shResult>-1</Get

System.Net Verbose: 0 : [1784] 00000140 : 4C 61 73 74 43 61 63 68-65 52 65 66 72 65 73 68 : LastCacheRefresh

System.Net Verbose: 0 : [1784] 00000150 : 52 65 73 75 6C 74 3E 3C-2F 47 65 74 4C 61 73 74 : Result></GetLast

System.Net Verbose: 0 : [1784] 00000160 : 43 61 63 68 65 52 65 66-72 65 73 68 52 65 73 70 : CacheRefreshResp

System.Net Verbose: 0 : [1784] 00000170 : 6F 6E 73 65 3E 3C 2F 73-6F 61 70 3A 42 6F 64 79 : onse></soap:Body

System.Net Verbose: 0 : [1784] 00000180 : 3E 3C 2F 73 6F 61 70 3A-45 6E 76 65 6C 6F 70 65 : ></soap:Envelope

System.Net Verbose: 0 : [1784] 00000190 : 3E : >

System.Net Verbose: 0 : [1784] Exiting ConnectStream#48313086::Read() -> 401#401

System.Net Verbose: 0 : [1784] ConnectStream#48313086::Read()

System.Net Verbose: 0 : [1784] Exiting ConnectStream#48313086::Read() -> 0#0

System.Net Verbose: 0 : [1784] ConnectStream#48313086::Close()

System.Net Verbose: 0 : [1784] Exiting ConnectStream#48313086::Close()

System.Net Error: 0 : [0188] Exception in the HttpWebRequest#5129585:: - The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.

System.Net Error: 0 : [0188] Exception in the HttpWebRequest#5129585::EndGetResponse - The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.

System.Net Verbose: 0 : [0188] WebRequest::Create(http://172.16.11.22/TaxApp/TaxProductWSAPI.asmx)

System.Net Verbose: 0 : [0188] HttpWebRequest#11162792::HttpWebRequest(http://172.16.11.22/TaxApp/TaxProductWSAPI.asmx#1920719121)

System.Net Verbose: 0 : [0188] Exiting HttpWebRequest#11162792::HttpWebRequest()

System.Net Verbose: 0 : [0188] Exiting WebRequest::Create() -> HttpWebRequest#11162792

System.Net Verbose: 0 : [0188] HttpWebRequest#11162792::GetRequestStream()

System.Net Information: 0 : [0188] Associating HttpWebRequest#11162792 with ServicePoint#4678310

System.Net Information: 0 : [0188] Associating Connection#8022616 with HttpWebRequest#11162792

System.Net Information: 0 : [0188] Associating HttpWebRequest#11162792 with ConnectStream#7077307

System.Net Verbose: 0 : [0188] Exiting HttpWebRequest#11162792::GetRequestStream() -> ConnectStream#7077307

System.Net Verbose: 0 : [0188] ConnectStream#7077307::Write()

System.Net Verbose: 0 : [0188] Data from ConnectStream#7077307::Write

System.Net Verbose: 0 : [0188] 00000000 : 3C 3F 78 6D 6C 20 76 65-72 73 69 6F 6E 3D 22 31 : <?xml version="1

System.Net Verbose: 0 : [0188] 00000010 : 2E 30 22 20 65 6E 63 6F-64 69 6E 67 3D 22 75 74 : .0" encoding="ut

System.Net Verbose: 0 : [0188] 00000020 : 66 2D 38 22 3F 3E 3C 73-6F 61 70 3A 45 6E 76 65 : f-8"?><soap:Enve

System.Net Verbose: 0 : [0188] 00000030 : 6C 6F 70 65 20 78 6D 6C-6E 73 3A 73 6F 61 70 3D : lope xmlns:soap=

System.Net Verbose: 0 : [0188] 00000040 : 22 68 74 74 70 3A 2F 2F-73 63 68 65 6D 61 73 2E : "http://schemas.

System.Net Verbose: 0 : [0188] 00000050 : 78 6D 6C 73 6F 61 70 2E-6F 72 67 2F 73 6F 61 70 : xmlsoap.org/soap

System.Net Verbose: 0 : [0188] 00000060 : 2F 65 6E 76 65 6C 6F 70-65 2F 22 20 78 6D 6C 6E : /envelope/" xmln

System.Net Verbose: 0 : [0188] 00000070 : 73 3A 78 73 69 3D 22 68-74 74 70 3A 2F 2F 77 77 : s:xsi="http://ww

System.Net Verbose: 0 : [0188] 00000080 : 77 2E 77 33 2E 6F 72 67-2F 32 30 30 31 2F 58 4D : w.w3.org/2001/XM

System.Net Verbose: 0 : [0188] 00000090 : 4C 53 63 68 65 6D 61 2D-69 6E 73 74 61 6E 63 65 : LSchema-instance

System.Net Verbose: 0 : [0188] 000000A0 : 22 20 78 6D 6C 6E 73 3A-78 73 64 3D 22 68 74 74 : " xmlns:xsd="htt

System.Net Verbose: 0 : [0188] 000000B0 : 70 3A 2F 2F 77 77 77 2E-77 33 2E 6F 72 67 2F 32 : p://www.w3.org/2

System.Net Verbose: 0 : [0188] 000000C0 : 30 30 31 2F 58 4D 4C 53-63 68 65 6D 61 22 3E 3C : 001/XMLSchema"><

System.Net Verbose: 0 : [0188] 000000D0 : 73 6F 61 70 3A 48 65 61-64 65 72 3E 3C 42 61 73 : soap:Header><Bas

System.Net Verbose: 0 : [0188] 000000E0 : 69 63 41 75 74 68 65 6E-74 69 63 61 74 69 6F 6E : icAuthentication

System.Net Verbose: 0 : [0188] 000000F0 : 48 65 61 64 65 72 20 78-6D 6C 6E 73 3D 22 68 74 : Header xmlns="ht

System.Net Verbose: 0 : [0188] 00000100 : 74 70 3A 2F 2F 63 6F 6D-2E 61 76 65 6E 69 74 79 : tp://com.avenity

System.Net Verbose: 0 : [0188] 00000110 : 2E 74 61 78 70 72 6F 64-75 63 74 2F 22 3E 3C 55 : .taxproduct/"><U

System.Net Verbose: 0 : [0188] 00000120 : 73 65 72 4E 61 6D 65 3E-4D 49 43 48 41 45 4C 3C : serName>MICHAEL<

System.Net Verbose: 0 : [0188] 00000130 : 2F 55 73 65 72 4E 61 6D-65 3E 3C 50 61 73 73 77 : /UserName><Passw

System.Net Verbose: 0 : [0188] 00000140 : 6F 72 64 3E 41 76 65 6E-69 74 79 3C 2F 50 61 73 : ord>Avenity</Pas

System.Net Verbose: 0 : [0188] 00000150 : 73 77 6F 72 64 3E 3C 2F-42 61 73 69 63 41 75 74 : sword></BasicAut

System.Net Verbose: 0 : [0188] 00000160 : 68 65 6E 74 69 63 61 74-69 6F 6E 48 65 61 64 65 : henticationHeade

System.Net Verbose: 0 : [0188] 00000170 : 72 3E 3C 2F 73 6F 61 70-3A 48 65 61 64 65 72 3E : r></soap:Header>

System.Net Verbose: 0 : [0188] 00000180 : 3C 73 6F 61 70 3A 42 6F-64 79 3E 3C 52 65 74 72 : <soap:Body><Retr

System.Net Verbose: 0 : [0188] 00000190 : 69 65 76 65 4D 65 73 73-61 67 65 73 46 6F 72 55 : ieveMessagesForU

System.Net Verbose: 0 : [0188] 000001A0 : 73 65 72 20 78 6D 6C 6E-73 3D 22 68 74 74 70 3A : ser xmlns="http:

System.Net Verbose: 0 : [0188] 000001B0 : 2F 2F 63 6F 6D 2E 61 76-65 6E 69 74 79 2E 74 61 : //com.avenity.ta

System.Net Verbose: 0 : [0188] 000001C0 : 78 70 72 6F 64 75 63 74-2F 22 3E 3C 75 73 65 72 : xproduct/"><user

System.Net Verbose: 0 : [0188] 000001D0 : 69 64 3E 31 3C 2F 75 73-65 72 69 64 3E 3C 2F 52 : id>1</userid></R

System.Net Verbose: 0 : [0188] 000001E0 : 65 74 72 69 65 76 65 4D-65 73 73 61 67 65 73 46 : etrieveMessagesF

System.Net Verbose: 0 : [0188] 000001F0 : 6F 72 55 73 65 72 3E 3C-2F 73 6F 61 70 3A 42 6F : orUser></soap:Bo

System.Net Verbose: 0 : [0188] 00000200 : 64 79 3E 3C 2F 73 6F 61-70 3A 45 6E 76 65 6C 6F : dy></soap:Envelo

System.Net Verbose: 0 : [0188] 00000210 : 70 65 3E 0D 0A : pe>..

System.Net Verbose: 0 : [0188] Exiting ConnectStream#7077307::Write()

System.Net Verbose: 0 : [0188] ConnectStream#7077307::Close()

System.Net Verbose: 0 : [0188] Exiting ConnectStream#7077307::Close()

System.Net Verbose: 0 : [0188] HttpWebRequest#11162792::GetResponse()

MichaelHogue at 2007-9-4 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...

.NET Development

Site Classified