Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

Microsoft.Exchange.WebServices - exception - service object doesn't have an Id.

$
0
0

In the code below FindAppointments throws an exception with the text:  this service object doesn't have an Id.

What am I doing wrong? 

 public class ExchangeCalendar
    {
        static bool RedirectionUrlValidationCallback(String redirectionUrl)
        {
            bool redirectionValidated = false;
            if (redirectionUrl.Equals("https://autodiscover-s.outlook.com/autodiscover/autodiscover.xml"))
                redirectionValidated = true;
            return redirectionValidated;
        } 

        public List<Appointment> FindAppointments(IUserData userData, DateTime startDate, DateTime endDate)
        {
            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
            service.Credentials = new WebCredentials(userData.EmailAddress, userData.Password);
            service.AutodiscoverUrl(userData.EmailAddress, RedirectionUrlValidationCallback); 

            CalendarFolder folder = new CalendarFolder(service);

            FindItemsResults<Appointment> findResults = folder.FindAppointments(
                new CalendarView(startDate, endDate))
            ;
            var list = new List<Appointment>();

            foreach (Appointment appointment in findResults.Items)
            {
                list.Add(appointment);
            }
            return list;
        }
    }

Exception Detail

System.InvalidOperationException was unhandled by user code
  HResult=-2146233079
  Message=This operation can't be performed because this service object doesn't have an Id.
  Source=Microsoft.Exchange.WebServices
  StackTrace:
       at Microsoft.Exchange.WebServices.Data.ServiceObject.ThrowIfThisIsNew()
       at Microsoft.Exchange.WebServices.Data.Folder.InternalFindItems[TItem](SearchFilter searchFilter, ViewBase view, Grouping groupBy)
       at Microsoft.Exchange.WebServices.Data.CalendarFolder.FindAppointments(CalendarView view)
       at ExchangeHelper.ExchangeCalendar.FindAppointments(IUserData userData, DateTime startDate, DateTime endDate) in c:\NewCode\ExchangeHelper\ExchangeHelper\ExchangeCalendar.cs:line 30
       at ScheduleWeb.Models.ExchangeToTimeSlot.GetAppintments(IUserData userData, DateTime startDate, DateTime endDate) in c:\NewCode\ScheduleWeb\ScheduleWeb\Models\ExchangeToTimeSlot.cs:line 15
       at ScheduleWeb.Models.CalendarModel.SetAvailableTimes() in c:\NewCode\ScheduleWeb\ScheduleWeb\Models\CalendarModel.cs:line 110
       at ScheduleWeb.Models.CalendarModel..ctor() in c:\NewCode\ScheduleWeb\ScheduleWeb\Models\CalendarModel.cs:line 59
       at ScheduleWeb.Controllers.CalendarController.Index() in c:\NewCode\ScheduleWeb\ScheduleWeb\Controllers\CalendarController.cs:line 17
       at lambda_method(Closure , ControllerBase , Object[] )
       at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
       at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41()
       at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
       at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33()
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
  InnerException:



Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>