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

转自:

http://www.outsystems.com/forums/discussion/15641/tip-the-underlying-connection-was-closed-an-unexpected-error-occurred-on-a-rece/

Symptom

You application is making a call to another system performing an HTTP(S) request. This request can be a:

  • Web service call (SOAP or REST)
  • A request to a specific web-page
  • Sending an email
  • ...

The call is failing and an error occurs in the application. In the Error Log you see an entry similar to (below example is for a SOAP web-reference):

[1] The underlying connection was closed: An unexpected error occurred on a receive.
   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 ssCRMApp.WRefPeopleLookup.WRefPeopleLookup.SearchByName(String search)
 
[2] Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
   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)
 
[3] An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
 


Cause
Errors like these happen because the remote server (to which the call was being made) did not deliver a response to your request and cut the connection before an answer could be sent. Meaning:

  1. Your application (the caller) sent the request
  2. While the application was waiting for the response, the remote server cut the connection.


Resolution
Resolving such a problem cannot be done on the caller side (your application) - you need to work with the party that provides the service for you.

If you are the other party or want to help: common causes on the other side for these errors are:

    • The request is taking too long to run and the server "times it out". If another OutSystems Platform is on the receiving end (meaning: the web call is to an OutSystems Platform) you may want to look here.
    • The remote server is having issues. E.g. application pool recycling or crashes that interrupt logic that may be runnning.
    • A network layer is cutting the network connection half-way. You may see errors in the remote server similar to this one (e.g. "could not flush response);
原文地址:https://www.cnblogs.com/iot1024/p/5013394.html