为什么通过 Exchange Web 服务 EWS API 访问邮箱随机失败?
Why accessing mailbox via Exchange Web Service EWS API fails randomly?
您好,我在使用 EWS API 访问 outloook Office 365 邮箱收件箱时遇到了这个问题。我正在使用 SSIS 包脚本任务到 运行 代码来连接到 Office365 上的 emailID,但它只是随机失败或 运行s 成功。
我已经实现如下
protected void ConnectToExchangeServer(string emailID, stringpassword)
{
ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
exchange = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
//exchange.Credentials = new WebCredentials("USERNAME", "PASSWORD", "DOMAIN");
exchange.Credentials = new WebCredentials(emailID, password);
//Hair splitting problem here in autodiscoverurl, sometimes runs successfully ,
//connects to inbox and reads mail and sometimes fails randomly
//throwing error Autodiscover could not find location.
exchange.AutodiscoverUrl(emailID, RedirectionUrlValidationCallback);
//exchange.Credentials = new WebCredentials("USERNAME", "PASSWORD", "DOMAIN");
//exchange.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
}
private static bool RedirectionUrlValidationCallback(){...}
private static bool CertificateValidationCallBack(object sender,
System.Security.Cryptography.X509Certificates.X509Certificate certificate,
System.Security.Cryptography.X509Certificates.X509Chain chain,
System.Net.Security.SslPolicyErrors sslPolicyErrors){..}
这个问题可能是什么原因造成的?我没有网络管理知识,所以请指导我如何检查我的请求被随机拒绝的问题?
您遇到的错误是 "The Autodiscovery service could not be located?" 不幸的是,这是一个可以掩盖潜在错误的包罗万象的错误。如果它是间歇性的,即相同的 SMTP+ 凭据有时有效而其他无效,则可能是超时情况。或者,如果您实际上是在程序的多个线程上调用同一个函数,一旦您同时调用了大约 20 个,EWS 就会开始用瞬态错误限制您。
了解问题所在的唯一方法是在 ExchangeService 对象上启用跟踪,并定义一个处理程序来打印出来自 AutodiscoverUrl 调用步骤的 XML。在网上很容易找到方法,而且添加起来也不错。如果这将是一个生产-class 应用程序,那么能够动态启用是件好事。
您好,我在使用 EWS API 访问 outloook Office 365 邮箱收件箱时遇到了这个问题。我正在使用 SSIS 包脚本任务到 运行 代码来连接到 Office365 上的 emailID,但它只是随机失败或 运行s 成功。 我已经实现如下
protected void ConnectToExchangeServer(string emailID, stringpassword)
{
ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
exchange = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
//exchange.Credentials = new WebCredentials("USERNAME", "PASSWORD", "DOMAIN");
exchange.Credentials = new WebCredentials(emailID, password);
//Hair splitting problem here in autodiscoverurl, sometimes runs successfully ,
//connects to inbox and reads mail and sometimes fails randomly
//throwing error Autodiscover could not find location.
exchange.AutodiscoverUrl(emailID, RedirectionUrlValidationCallback);
//exchange.Credentials = new WebCredentials("USERNAME", "PASSWORD", "DOMAIN");
//exchange.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
}
private static bool RedirectionUrlValidationCallback(){...}
private static bool CertificateValidationCallBack(object sender,
System.Security.Cryptography.X509Certificates.X509Certificate certificate,
System.Security.Cryptography.X509Certificates.X509Chain chain,
System.Net.Security.SslPolicyErrors sslPolicyErrors){..}
这个问题可能是什么原因造成的?我没有网络管理知识,所以请指导我如何检查我的请求被随机拒绝的问题?
您遇到的错误是 "The Autodiscovery service could not be located?" 不幸的是,这是一个可以掩盖潜在错误的包罗万象的错误。如果它是间歇性的,即相同的 SMTP+ 凭据有时有效而其他无效,则可能是超时情况。或者,如果您实际上是在程序的多个线程上调用同一个函数,一旦您同时调用了大约 20 个,EWS 就会开始用瞬态错误限制您。
了解问题所在的唯一方法是在 ExchangeService 对象上启用跟踪,并定义一个处理程序来打印出来自 AutodiscoverUrl 调用步骤的 XML。在网上很容易找到方法,而且添加起来也不错。如果这将是一个生产-class 应用程序,那么能够动态启用是件好事。