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

时间:2009-10-22 16:30:55

标签: c#

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

这也是我在这里发表的第一篇文章,请原谅。

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

这是一个间歇性问题,很难再现。 我正在运行的代码只是调用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<{0}\{1}>", userNTDomain, userIntranetID), groupLookupException);
 }
 finally
 {
     if ( groupResponse != null )
     {
         groupResponse.Close();
     }
 }

以下是有时发生的错误:

Could not find groups for user<DOMAIN\auser> ---> 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次

1 个答案:

答案 0 :(得分:8)

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