首页 > 解决方案 > EWS:InvalidOperationException / ServiceResponseException

问题描述

我有一个 EWS 同步器,在我的公司进行了一些撤消操作后,该同步器已停止工作。它无法编辑或更新其他员工的邮件,并说缺少日历的特权/权利。它在 2 周前工作,代码没有任何变化,我检查并查看 SID 已更改,但我更新了它,仍然给我缺少权限错误。我没有写这个,但我负责维护这个同步器程序,所以如果我在黑暗中听起来有点,请原谅。

服务响应异常

else if (ex.InnerException is ServiceResponseException)
                                                                 {
                                                                     if (ex.InnerException.Message.ValueIn("The SMTP address has no mailbox associated with it.", "The specified folder could not be found in the store."))
                                                                     {
                                                                         a.ExchangeSyncronizationSettings.HasCalendarEditorPermission = false;
                                                                         a.ExchangeSyncronizationSettings.Save(conn);

                                                                         Console.WriteLine("Rettigheder til kalender mangler for " + a.Initials);
                                                                         permissionEx.Add(a.Initials);
                                                                     }

无效操作异常

} catch(Exception ex) {
                                                         if(ex.InnerException != null) {
                                                             if(ex.InnerException is InvalidOperationException) {
                                                                 if(ex.InnerException.Message == "Agent has not assigned editor permissions") {
                                                                     a.ExchangeSyncronizationSettings.HasCalendarEditorPermission = false;
                                                                     a.ExchangeSyncronizationSettings.Save(conn);

                                                                     Console.WriteLine("Rettigheder til kalender mangler for " + a.Initials);
                                                                     permissionEx.Add(a.Initials);
                                                                 } else
                                                                     exceptions.Add(ex.InnerException);

HasCalendarEditorPermissions

private bool HasCalendarEditorPermissions(Folder calendar, string userSID) {
        if(calendar == null)
            throw new ArgumentNullException("calendar");

        if(calendar.GetLoadedPropertyDefinitions().Contains(FolderSchema.Permissions))
            SendExchangeRequest(() => calendar.Load(new PropertySet(FolderSchema.Permissions)));

        return calendar.Permissions.Any(p => p.UserId.SID == userSID &&
                                             p.DisplayPermissionLevel == FolderPermissionLevel.Editor);
    }

编辑

    private Folder GetAgentCalendar(ExchangeService service, SAFEAgent agent) {
        string username = agent.EmailAddress;

        var calendar = SendExchangeRequest(() => Folder.Bind(service, new FolderId(WellKnownFolderName.Calendar, username)));

       // if(!HasCalendarEditorPermissions(calendar, SC01_SID))
         //   throw new InvalidOperationException("Agent has not assigned editor permissions");

        agent.ExchangeSyncronizationSettings.HasCalendarEditorPermission = true;

        return calendar;
    }

基本上,当我注释掉以下内容时,它会再次运行我的同步器,但是自从两周前工作以来发生了什么变化?

使程序再次运行的未注释代码

// if(!HasCalendarEditorPermissions(calendar, SC01_SID))
         //   throw new InvalidOperationException("Agent has not assigned editor permissions");

标签: exchange-serverexchangewebservicesexchange-server-2010

解决方案


推荐阅读