已建立的连接已被主机中的软件中止

对不起,如果这有点长的啰嗦,但我认为更好的发布更多。

这也是我的第一篇post,请原谅。

我一直在努力想出这个问题。 并且无济于事,希望有一个天才在那里遇到过这个。

这是一个间歇性问题,很难再现。 我正在运行的代码只是调用Web服务Web服务调用是循环的(所以我们可以这么做,1500次或更多)

以下是导致错误的代码:

HttpWebRequest groupRequest = null; WebResponse groupResponse = null; try { XmlDocument doc = new XmlDocument(); groupRequest = (HttpWebRequest)HttpWebRequest.Create(String.Format(Server.HtmlDecode(Util.GetConfigValue("ImpersonatedSearch.GroupLookupUrl")),userIntranetID)); groupRequest.Proxy = null; groupRequest.KeepAlive = false; groupResponse = groupRequest.GetResponse(); doc.Load(groupResponse.GetResponseStream()); foreach (XmlElement nameElement in doc.GetElementsByTagName(XML_GROUP_NAME)) { foreach (string domain in _groupDomains ) { try { string group = new System.Security.Principal.NTAccount(domain, nameElement.InnerText).Translate(typeof(System.Security.Principal.SecurityIdentifier)).Value; impersonationChain.Append(";").Append(group); break; } catch{} } // loop through } } catch (Exception groupLookupException) { throw new ApplicationException(String.Format(@"Impersonated Search ERROR: Could not find groups for user", userNTDomain, userIntranetID), groupLookupException); } finally { if ( groupResponse != null ) { groupResponse.Close(); } } 

以下是有时发生的错误:

 Could not find groups for user ---> System.IO.IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine 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.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Xml.XmlTextReaderImpl.ReadData() at System.Xml.XmlTextReaderImpl.ParseDocumentContent() at System.Xml.XmlLoader.LoadDocSequence (XmlDocument parentDoc) at System.Xml.XmlDocument.Load(XmlReader reader) at System.Xml.XmlDocument.Load(Stream inStream) at MyWebServices.ImpersonatedSearch.PerformQuery(QueryParameters parameters, String userIntranetID, String userNTDomain)--- End of inner exception stack trace ---at MyWebServices.ImpersonatedSearch.PerformQuery(QueryParameters parameters, String userIntranetID, String userNTDomain) --- End of inner exception stack trace --- at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at MyProgram. MyWebServices.ImpersonatedSearch.PerformQuery (QueryParameters parameters, String userIntranetID, String userNTDomain) at MyProgram.MyMethod() 

很抱歉,有很多代码需要通读。
这种情况大约在1700年左右发生30次

你可能会超时。 首先,重新打开keepalive。 其次,检查请求上的时间戳并回复。 如果发送方和接收方之间存在防火墙,请确保由于空闲超时而未关闭连接。 我以前遇到过这两个问题,虽然使用通用套接字编程,而不是DB的东西。