【发布时间】:2014-03-25 05:46:01
【问题描述】:
我们有一个 Exchange Server 2010 SP2 在本地运行。
我正在使用 EWS 托管 API(我已经尝试过 API/DLL 版本 1.2 和 2.1)来连接它。我能够检索日历、EWS 服务名称和版本信息,但在“var appointments = calendar.FindAppointments(calenderView);”线上我得到一个 501 - Not Implement 异常(见图)。
我已经在网上搜索过,但找不到有关此错误的任何信息,也没有在 MSDN 上找到信息。 下面是我使用的代码:
主要方法:
private void Main_Load(object sender, EventArgs e)
{
ConnectWithExchange();
GetCalendarItems();
}
实例化
/// <summary>
/// http://msdn.microsoft.com/en-us/library/office/ff597939(v=exchg.80).aspx
/// </summary>
private void ConnectWithExchange()
{
// 01. Instantiate ExchangeService
_exchange = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
// 02. Connect with credentials
_exchange.UseDefaultCredentials = true;
// or pass through credentials of a service user:
// _exchange.Credentials = new WebCredentials("user@name", "password", "domain");
// 03. Set correct endpoint
// http://msdn.microsoft.com/en-us/library/office/gg274410(v=exchg.80).aspx
// _exchange.Url = new Uri("https://outlook.kdg.be/EWS/Exchange.asmx");
// or use autodiscover
_exchange.AutodiscoverUrl("name@domain.com"); // works ok
// 04. Display version and info
UxExchangeVersion.Text = _exchange.Url.ToString(); // works ok
}
检索日历项目
/// <summary>
/// http://msdn.microsoft.com/en-us/library/office/dn439786(v=exchg.80).aspx
/// </summary>
private void GetCalendarItems()
{
// 01. Init calendar folder object with the folder ID
CalendarFolder calendar = CalendarFolder.Bind(_exchange, WellKnownFolderName.Calendar, new PropertySet(FolderSchema.DisplayName));
// 02. Set start and end time and number of appointments to retrieve
CalendarView calenderView = new CalendarView(DateTime.Now, DateTime.Now.AddDays(7), 150);
// 03. Limit the properties returned
calenderView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);
// 04. Fetch the appointments
var appointments = calendar.FindAppointments(calenderView);
// var appointments = _exchange.FindAppointments(calendar.Id, new CalendarView(DateTime.Now, DateTime.Now.AddDays(7))); // **failure point**
// 05. Display appiontments in list
// 05A. Fetch calender name
uxCalenderName.Text = calendar.DisplayName + " (" + calendar.Id.Mailbox + ")";
// 05B. Fill list
uxAppointments.Items.Clear();
foreach (var appointment in appointments)
{
var appointmentString = new StringBuilder();
appointmentString.Append("Subject: " + appointment.Subject.ToString() + " ");
appointmentString.Append("Start: " + appointment.Start.ToString() + " ");
appointmentString.Append("End: " + appointment.End.ToString());
uxAppointments.Items.Add(appointmentString.ToString());
}
}
【问题讨论】:
标签: c# exchange-server exchangewebservices