【发布时间】:2017-05-05 23:10:11
【问题描述】:
长期潜伏者,第一次海报。
我已经看到很多关于通过 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,我也尝试检查调试/test 无济于事)。我正在检查四个不同的日历,并且同一行中的任何一个都可能发生此错误。我看不出我的代码有什么问题,所以真的很沮丧。
首先我初始化一些东西来准备要发送的电子邮件:
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。无论哪种方式,它似乎都没有改变任何东西。
错误可能发生在电子邮件初始化或日历检查期间,但两次 iirc 都在 .AutodiscoverUrl 行。我正在通过 Rackspace 托管的测试盒运行它,如果这很重要的话。
非常感谢任何帮助,谢谢!
【问题讨论】:
标签: c# exchange-server