由于未处理的异常,进程已终止。 System.Net.HttpWebRequest.GetResponse() ews 异常
The process was terminated due to an unhandled exception. System.Net.HttpWebRequest.GetResponse() exception in ews
大家好,我遇到了这个异常,它正在停止我的服务。请帮助以下是完整的堆栈跟踪。
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Net.WebException at System.Net.HttpWebRequest.GetResponse()
at
Microsoft.Exchange.WebServices.Data.EwsHttpWebRequest.Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest.GetResponse()
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest)
Exception Info: Microsoft.Exchange.WebServices.Data.ServiceRequestException
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest)
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest ByRef)
at Microsoft.Exchange.WebServices.Data.HangingServiceRequestBase.InternalExecute()
at Microsoft.Exchange.WebServices.Data.StreamingSubscriptionConnection.Open()
at ERSupportGetOutlookEmail.EmailExchange.OnDisconnect(System.Object, Microsoft.Exchange.WebServices.Data.SubscriptionErrorEventArgs)
at Microsoft.Exchange.WebServices.Data.StreamingSubscriptionConnection.InternalOnDisconnect(System.Exception)
at Microsoft.Exchange.WebServices.Data.StreamingSubscriptionConnection.OnRequestDisconnect(System.Object, Microsoft.Exchange.WebServices.Data.HangingRequestDisconnectEventArgs)
at Microsoft.Exchange.WebServices.Data.HangingServiceRequestBase.InternalOnDisconnect(Microsoft.Exchange.WebServices.Data.HangingRequestDisconnectReason, System.Exception)
at Microsoft.Exchange.WebServices.Data.GetStreamingEventsResponse.ReadElementsFromXml(Microsoft.Exchange.WebServices.Data.EwsServiceXmlReader)
at Microsoft.Exchange.WebServices.Data.ServiceResponse.LoadFromXml(Microsoft.Exchange.WebServices.Data.EwsServiceXmlReader, System.String)
at Microsoft.Exchange.WebServices.Data.GetStreamingEventsRequest.ParseResponse(Microsoft.Exchange.WebServices.Data.EwsServiceXmlReader)
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ReadResponse(Microsoft.Exchange.WebServices.Data.EwsServiceXmlReader)
at Microsoft.Exchange.WebServices.Data.HangingServiceRequestBase.ParseResponses(System.Object)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
这是我的代码,请查看这个
public async System.Threading.Tasks.Task Watch()
{
//Configuration options for a public client application (desktop/mobile app)
var pcaOptions = new PublicClientApplicationOptions
{
ClientId = ConfigurationManager.AppSettings["appId"],
TenantId = ConfigurationManager.AppSettings["tenantId"]
};
//Creates a PublicClientApplicationBuilder from a clientID.
var pca = PublicClientApplicationBuilder
.CreateWithApplicationOptions(pcaOptions).Build();
//access permission.
var ewsScopes = new string[] { "https://outlook.office.com/EWS.AccessAsUser.All" };
try
{
// Make the interactive token request
var authResult = await pca.AcquireTokenByUsernamePassword(ewsScopes, EmailID, ConvertToSecureString(Password)).ExecuteAsync();
//var authResult = await pca.AcquireTokenInteractive(ewsScopes).ExecuteAsync();
// Configure the ExchangeService with the access token
ewsClient = new ExchangeService();
ewsClient.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
ewsClient.Credentials = new OAuthCredentials(authResult.AccessToken);
Console.WriteLine("New Email details will display below:-");
// Make an EWS call
CreateStreamingSubscription(); //Creating subscription.
}
catch (MsalException ex)
{
Email.onErrorOccur(ex.Message, "EmailExchange Watch event MsalException", ex.StackTrace);
}
catch (Exception ex)
{
Email.onErrorOccur(ex.Message, "EmailExchange Watch event", ex.StackTrace);
}
}
在您发布的导致异常的 CreateStreamingSubscription 中的代码中,它只是被您发布的代码块捕获,该代码块不执行任何 Exchange 请求,仅进行身份验证。您能否提供有关何时发生的更多详细信息,例如,代码可以工作一段时间,然后发生这种情况,还是只是不起作用?如果它只是不起作用可能 TLS 1.2 所以我建议包括在
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
大家好,我遇到了这个异常,它正在停止我的服务。请帮助以下是完整的堆栈跟踪。
Description: The process was terminated due to an unhandled exception. Exception Info: System.Net.WebException at System.Net.HttpWebRequest.GetResponse() at Microsoft.Exchange.WebServices.Data.EwsHttpWebRequest.Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest.GetResponse() at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest)
Exception Info: Microsoft.Exchange.WebServices.Data.ServiceRequestException at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest) at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest ByRef) at Microsoft.Exchange.WebServices.Data.HangingServiceRequestBase.InternalExecute() at Microsoft.Exchange.WebServices.Data.StreamingSubscriptionConnection.Open() at ERSupportGetOutlookEmail.EmailExchange.OnDisconnect(System.Object, Microsoft.Exchange.WebServices.Data.SubscriptionErrorEventArgs) at Microsoft.Exchange.WebServices.Data.StreamingSubscriptionConnection.InternalOnDisconnect(System.Exception) at Microsoft.Exchange.WebServices.Data.StreamingSubscriptionConnection.OnRequestDisconnect(System.Object, Microsoft.Exchange.WebServices.Data.HangingRequestDisconnectEventArgs) at Microsoft.Exchange.WebServices.Data.HangingServiceRequestBase.InternalOnDisconnect(Microsoft.Exchange.WebServices.Data.HangingRequestDisconnectReason, System.Exception) at Microsoft.Exchange.WebServices.Data.GetStreamingEventsResponse.ReadElementsFromXml(Microsoft.Exchange.WebServices.Data.EwsServiceXmlReader) at Microsoft.Exchange.WebServices.Data.ServiceResponse.LoadFromXml(Microsoft.Exchange.WebServices.Data.EwsServiceXmlReader, System.String) at Microsoft.Exchange.WebServices.Data.GetStreamingEventsRequest.ParseResponse(Microsoft.Exchange.WebServices.Data.EwsServiceXmlReader) at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ReadResponse(Microsoft.Exchange.WebServices.Data.EwsServiceXmlReader) at Microsoft.Exchange.WebServices.Data.HangingServiceRequestBase.ParseResponses(System.Object) at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object) at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
这是我的代码,请查看这个
public async System.Threading.Tasks.Task Watch()
{
//Configuration options for a public client application (desktop/mobile app)
var pcaOptions = new PublicClientApplicationOptions
{
ClientId = ConfigurationManager.AppSettings["appId"],
TenantId = ConfigurationManager.AppSettings["tenantId"]
};
//Creates a PublicClientApplicationBuilder from a clientID.
var pca = PublicClientApplicationBuilder
.CreateWithApplicationOptions(pcaOptions).Build();
//access permission.
var ewsScopes = new string[] { "https://outlook.office.com/EWS.AccessAsUser.All" };
try
{
// Make the interactive token request
var authResult = await pca.AcquireTokenByUsernamePassword(ewsScopes, EmailID, ConvertToSecureString(Password)).ExecuteAsync();
//var authResult = await pca.AcquireTokenInteractive(ewsScopes).ExecuteAsync();
// Configure the ExchangeService with the access token
ewsClient = new ExchangeService();
ewsClient.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
ewsClient.Credentials = new OAuthCredentials(authResult.AccessToken);
Console.WriteLine("New Email details will display below:-");
// Make an EWS call
CreateStreamingSubscription(); //Creating subscription.
}
catch (MsalException ex)
{
Email.onErrorOccur(ex.Message, "EmailExchange Watch event MsalException", ex.StackTrace);
}
catch (Exception ex)
{
Email.onErrorOccur(ex.Message, "EmailExchange Watch event", ex.StackTrace);
}
}
在您发布的导致异常的 CreateStreamingSubscription 中的代码中,它只是被您发布的代码块捕获,该代码块不执行任何 Exchange 请求,仅进行身份验证。您能否提供有关何时发生的更多详细信息,例如,代码可以工作一段时间,然后发生这种情况,还是只是不起作用?如果它只是不起作用可能 TLS 1.2 所以我建议包括在
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12