[英]C# intermittent “The Autodiscover service couldn't be located”
长期潜伏,第一次海报。
我已经看到很多有关通过Exchange2010模拟的问题(这是我正在做的事情),但是到目前为止,我所看到的一切都与无效的代码语法或无效的密码有关。 希望有人可以帮助我解决我的问题,这有点奇怪。 我只是想发送一封电子邮件,从同一域的另一个日历中获取约会,然后发送列出了这些约会的电子邮件。
我的代码有效,但偶尔会出现以下错误:
An unhandled exception of type 'Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException' occurred in Microsoft.Exchange.WebServices.dll
Additional information: The Autodiscover service couldn't be located.
我故意从代码中删除了任何错误检查,并使其在运行时崩溃。 如果我立即重试,则可能会或可能不会。 如果五分钟后重试,则显示相同的故事。 大约有75%的时间在第一次运行时有效,而且对我而言,我无法弄清楚自己在做错什么(错误指向RedirectionUrlValidationCallback,我也尝试对其进行调试检查) /测试无济于事)。 我正在检查四个不同的日历,并且在同一行中的任何一个上都可能发生此错误。 我看不到我的代码有什么问题,所以这真令人沮丧。
首先,我初始化东西以准备发送电子邮件:
using Microsoft.Exchange.WebServices.Data;
const int NUM_APPTS = 10;
ExchangeService serviceAuth = new ExchangeService(ExchangeVersion.Exchange2010);
serviceAuth.Credentials = new WebCredentials("me@mydomain.com", "PASSHERE");
serviceAuth.AutodiscoverUrl("me@mydomain.com", RedirectionUrlValidationCallback);
我写了电子邮件,等等,然后去检查日历并尝试查看条目:
ExchangeService serviceCALONE = new ExchangeService(ExchangeVersion.Exchange2010);
serviceCALONE.Credentials = new WebCredentials("CALONE@mydomain.com", "PASSHERE");
serviceCALONE.AutodiscoverUrl("CALONE@mydomain.com", RedirectionUrlValidationCallback);
CalendarFolder calendarCALONE = CalendarFolder.Bind(serviceCALONE, WellKnownFolderName.Calendar, new PropertySet());
CalendarView cViewCALONE = new CalendarView(startDate, endDate, NUM_APPTS);
cViewCALONE.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);
FindItemsResults<Appointment> appointmentsCALONE = calendarCALONE.FindAppointments(cViewCALONE);
这是我在MSDN上其他地方使用的RedirectionURLValidationCallback函数:
private static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
// The default for the validation callback is to reject the URL.
bool result = true;
// This was changed to default to true because an error started appearing with:
// "The autodiscover service could not be located"
Uri redirectionUri = new Uri(redirectionUrl);
if (redirectionUri.Scheme == "https")
{
result = true;
}
return result;
}
如您所见(除了我在学习过程中对自己发表评论的事实之外),无论如何我都尝试返回true。 似乎没有任何改变的方式。
该错误可能在电子邮件初始化或日历检查期间发生,但两次都在.AutodiscoverUrl行上。 如果重要的话,我正在通过Rackspace托管的测试盒上运行它。
非常感谢任何帮助,谢谢!
尝试使用以下格式的Service.Credentials
:
Service.Credentials = new WebCredentials(username, password, domainname);
另外,检查电子邮件地址的密码是否已过期。 如果密码已过期,您将从自动发现中收到此错误。
外部测试自动发现的另一种故障排除选项是使用Microsoft远程连接分析器 。
如果所有其他方法均失败,建议您启用跟踪以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.