0

I'm using the following code to return items from the calendar. When I connect with the user's actual credentials, I get 10 items back, as expected. When I connect as the service account, I always get 0. The service account has the right privileges to view and update the user's calendar. Why isn't it returning any results?

            // Connect to Exchange Web Services
            service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);

            --> service.Credentials = new WebCredentials("svc_user", "svc_password", "domain");
            --> //service.Credentials = new WebCredentials("user", "password", "domain");
            service.AutodiscoverUrl("user@domain");

            //Return count
            ItemView view = new ItemView(10);
            view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
            FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Calendar, view);
            MessageBox.Show(findResults.Count().ToString());
4

1 回答 1

0

我必须给服务一个价值ImpersonatedUserId

        // Connect to Exchange Web Services
        service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);

        service.Credentials = new WebCredentials("svc_user", "svc_password", "domain");
        service.AutodiscoverUrl("user@domain");
        service.ImpersonatedUserId = new ImpersonatedUserID(ConnectingIdType.SmtpAddres, "user@domain");

        //Return count
        ItemView view = new ItemView(10);
        view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
        FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Calendar, view);
        MessageBox.Show(findResults.Count().ToString());

我的假设是,通过在用户商店上运行 Autodiscover,默认情况下会发生模拟。

于 2013-08-26T17:14:55.683 回答