gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 08:26:39 24 4
gpt4 key购买 nike

抱歉,如果这有点啰嗦,但我认为多发帖总比少发帖好。

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

一段时间以来,我一直在努力解决这个问题。无济于事,希望那里有一个以前遇到过这种情况的天才。

这是一个间歇性问题,很难重现。我正在运行的代码只是调用一个网络服务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 次

最佳答案

您可能遇到了超时。首先,重新打开keepalive。其次,检查请求和回复的时间戳。如果发送方和接收方之间存在防火墙,请确保它不会因为空闲超时而关闭连接。我过去遇到过这两个问题,尽管使用的是通用套接字编程,而不是数据库的东西。

关于c# - 已建立的连接被主机中的软件中止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1608431/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com