Yves Schelpe
Yves Schelpe

Reputation: 3463

Exchange WebService EWS FindAppointmens 501: Not Implemented

We have an Exchange Server 2010 SP2 running here on premise. I'm using the EWS Managed API (I've tried both API/DLL version 1.2 and 2.1) to connect to it. I'm able to retrieve calendar, EWS Service name and version info, but on line "var appointments = calendar.FindAppointments(calenderView);" I get a 501 - Not Implement exception (see image).

enter image description here

I've searched the net but can't find any info on this error, nor do I find info on MSDN. Below is the code I use:

Main Method:

        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("[email protected]"); // works ok

            // 04. Display version and info
            UxExchangeVersion.Text = _exchange.Url.ToString(); // works ok           
        }

Retrieving Calendar Items

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

Upvotes: 0

Views: 844

Answers (1)

Michael Mainer
Michael Mainer

Reputation: 3465

I ran GetCalendarItems() and it works fine for me. I noticed that you don't have the URL redirection callback in _exchange.AutodiscoverUrl. I'm surprised that you can get the URL without a redirection.

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;
}

Can you tell me about your target server? What version of Exchange are you targeting?

Upvotes: 1

Related Questions