An existing connection was forcibly closed by the remote host

W

Wil Peck

So here is the scenario...

I have a console application executing a Web Method on my WSDL generated
System.Web.Protocols.SoapHttpClientProtocol instance using HTTP over a VPN.
For some reason requests that are larger than 1024 bytes are timing out and
the stack trace ends up being something like the above. I can't find where
there are any maxRequestLength (that applies to requests a client makes to a
web service) that can be adjusted to accommodate for larger requests.

Below is an snippet of the stack trace minus any proprietary info.

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
connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32
size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset,
Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset,
Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean
userRetrievedStream, Boolean probeRead)
--- End of inner exception 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)

I have done a trace on the System.Net.Sockets which seems to show that the
request wasn't really completed by the SoapHttpClientProtocol instance.
Please note that this was working fine until we applied patches to our Win2k
machine and then after the patches were applied it stopped working. I have
been able to get the service to work on WinXP fully patched, but not on
Windows Server 2k3 or Win Server 2k.

My hunch is the request is never fully written to the host of the web
service and the web service finally decides to close the connection because
it received an incomplete message. In an attempt to give the request more
time to complete I have increased the WebClientProtocol.Timeout to 2 minutes
without any success. If anyone has any other ideas on this it would be
greatly appreciated.

Thanks - Wil
 
W

Wil Peck

I finally figured out how to address this specific issue. Within my web
service proxy class I overrode the GetWebRequest(uri) method and modified it
as shown below.

protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest request = base.GetWebRequest(uri) as
HttpWebRequest;
request.SendChunked = true;
return request;
}

What I still haven't taken the time to figure out is why this behavior
changed after we applied windows service packs to our machine. If the size
of the request message I was using is greater than the size of the packets
the host could receive and the host is configured receive chunked messages
then I guess I can assume (I hate assuming things) when we sent a message
larger than the packet size without sending it chunked their server
terminated the session because it was waiting for another TCP message???

Hard to tell without being able to easily work with the web service host
directly. At any rate I hope this helps anyone else who encounters the same
problem.

Wil Peck said:
So here is the scenario...

I have a console application executing a Web Method on my WSDL generated
System.Web.Protocols.SoapHttpClientProtocol instance using HTTP over a
VPN. For some reason requests that are larger than 1024 bytes are timing
out and the stack trace ends up being something like the above. I can't
find where there are any maxRequestLength (that applies to requests a
client makes to a web service) that can be adjusted to accommodate for
larger requests.

Below is an snippet of the stack trace minus any proprietary info.

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 connection was forcibly
closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32
size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset,
Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset,
Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean
userRetrievedStream, Boolean probeRead)
--- End of inner exception 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)

I have done a trace on the System.Net.Sockets which seems to show that the
request wasn't really completed by the SoapHttpClientProtocol instance.
Please note that this was working fine until we applied patches to our
Win2k machine and then after the patches were applied it stopped working.
I have been able to get the service to work on WinXP fully patched, but
not on Windows Server 2k3 or Win Server 2k.

My hunch is the request is never fully written to the host of the web
service and the web service finally decides to close the connection
because it received an incomplete message. In an attempt to give the
request more time to complete I have increased the
WebClientProtocol.Timeout to 2 minutes without any success. If anyone has
any other ideas on this it would be greatly appreciated.

Thanks - Wil
 
W

Wil Peck

I finally figured out how to address this specific issue. Within my web
service proxy class I overrode the GetWebRequest(uri) method and modified it
as shown below.

protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest request = base.GetWebRequest(uri) as
HttpWebRequest;
request.SendChunked = true;
return request;
}

What I still haven't taken the time to figure out is why this behavior
changed after we applied windows service packs to our machine. If the size
of the request message I was using is greater than the size of the packets
the host could receive and the host is configured receive chunked messages
then I guess I can assume (I hate assuming things) when we sent a message
larger than the packet size without sending it chunked their server
terminated the session because it was waiting for another TCP message???

Hard to tell without being able to easily work with the web service host
directly. At any rate I hope this helps anyone else who encounters the same
problem.


Wil Peck said:
So here is the scenario...

I have a console application executing a Web Method on my WSDL generated
System.Web.Protocols.SoapHttpClientProtocol instance using HTTP over a
VPN. For some reason requests that are larger than 1024 bytes are timing
out and the stack trace ends up being something like the above. I can't
find where there are any maxRequestLength (that applies to requests a
client makes to a web service) that can be adjusted to accommodate for
larger requests.

Below is an snippet of the stack trace minus any proprietary info.

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 connection was forcibly
closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32
size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset,
Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset,
Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean
userRetrievedStream, Boolean probeRead)
--- End of inner exception 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)

I have done a trace on the System.Net.Sockets which seems to show that the
request wasn't really completed by the SoapHttpClientProtocol instance.
Please note that this was working fine until we applied patches to our
Win2k machine and then after the patches were applied it stopped working.
I have been able to get the service to work on WinXP fully patched, but
not on Windows Server 2k3 or Win Server 2k.

My hunch is the request is never fully written to the host of the web
service and the web service finally decides to close the connection
because it received an incomplete message. In an attempt to give the
request more time to complete I have increased the
WebClientProtocol.Timeout to 2 minutes without any success. If anyone has
any other ideas on this it would be greatly appreciated.

Thanks - Wil
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top