문제

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());
도움이 되었습니까?

해결책

I had to give the service a value for 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());

My assumption was that by running Autodiscover on the user's store, the impersonation would happen by default.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top