【发布时间】:2017-12-26 11:06:09
【问题描述】:
我有一个 Windows 服务应用程序,它将一些消息发送到另一个网络服务(实习生作为电子邮件发送)并从服务器下载响应。
最近,服务每隔几天就会停止一次。 (尽管包含了一些异常处理,但它仍然没有被捕获并且服务正在崩溃)。
在事件查看器中登录的异常如下:
框架版本:v4.0.30319 描述:进程被终止 由于未处理的异常。异常信息:System.Net.WebException 堆栈:在 System.Net.ServicePointManager.FindServicePoint(System.Uri, System.Net.IWebProxy,System.Net.ProxyChain ByRef, System.Net.HttpAbortDelegate ByRef, Int32 ByRef) 在 System.Net.HttpWebRequest.FindServicePoint(Boolean) 在 System.Net.HttpWebRequest.get_ServicePoint() 在 System.Net.AuthenticationState.PrepareState(System.Net.HttpWebRequest) 在 System.Net.AuthenticationState.ClearSession(System.Net.HttpWebRequest) 在 System.Net.HttpWebRequest.ClearAuthenticatedConnectionResources()
在 System.Net.HttpWebRequest.Abort(System.Exception, Int32) 在 System.Net.HttpWebRequest.AbortWrapper(System.Object) 在 System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 在 System.Threading.ThreadPoolWorkQueue.Dispatch() 在 System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
我搜索了很多,但找不到正确的答案。 任何帮助,将不胜感激。使用的代码:
public class DataAPIWebClient : WebClient
{
protected override WebRequest GetWebRequest(Uri uri)
{
WebRequest w = base.GetWebRequest(uri);
w.Timeout = 60000;
return w;
}
}
public string Send(string path)
{
try
{
using (DataAPIWebClient webClient = new DataAPIWebClient())
{
webClient.Credentials = new NetworkCredential("XXX", "YYY");
string reply = webClient.DownloadString(path);
return reply;
}
}
catch (WebException)
{
throw;
}
}
【问题讨论】: