Exchange Web服务EWS FindAppointments 501:未实现

时间:2014-03-24 14:31:58

标签: c# exchange-server exchangewebservices

我们在此处运行 Exchange Server 2010 SP2 。 我正在使用 EWS托管API (我已经尝试过两种API / DLL版本1.2和2.1)来连接它。我能够检索日历,EWS服务名称和版本信息,但在线" var appointments = calendar.FindAppointments(calenderView);"我得到501 - Not Implement异常(见图)。

enter image description here

我已在网上搜索但无法找到有关此错误的任何信息,也无法在MSDN上找到相关信息。 以下是我使用的代码:

主要方法:

        private void Main_Load(object sender, EventArgs e)
        {
            ConnectWithExchange();
            GetCalendarItems();
        }

Instantation

        /// <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());
            }
        }

1 个答案:

答案 0 :(得分:1)

我运行了GetCalendarItems(),它对我来说很好。我注意到您在_exchange.AutodiscoverUrl中没有URL重定向回调。我很惊讶您可以在没有重定向的情况下获取URL。

internal static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
    // The default for the validation callback is to reject the URL.
    bool result = false;

    Uri redirectionUri = new Uri(redirectionUrl);

    // Validate the contents of the redirection URL. In this simple validation
    // callback, the redirection URL is considered valid if it is using HTTPS
    // to encrypt the authentication credentials. 
    if (redirectionUri.Scheme == "https")
    {
        result = true;
    }

    return result;
}

您能告诉我您的目标服务器吗?您定位的是什么版本的Exchange?