Exchange 2010 和应用程序模拟问题

Exchange 2010 and Application Impersonation Issue

我正在尝试在 Exchange 2010 中设置应用程序模拟以允许 .NET 应用程序能够 read/update 我的组织的日历。

到目前为止,我已经创建了一个服务帐户和一个角色分配

New-ManagementRoleAssignment -Name:myServiceCalendar -Role:ApplicationImpersonation -User:myService

但是,当我去实际访问一个帐户的日历时,我得到一个 ErrorFolderNotFound

这是我用于测试的代码

        var _testUserName = "myService@contoso.com";
        var _testUser = new WebCredentials(_testUserName, "Apass@wordForYou");

        var service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);

        service.Credentials = _testUser;

        service.TraceEnabled = true;
        service.TraceFlags = TraceFlags.All;

        service.AutodiscoverUrl(_testUserName);

        var testCalendar = new Mailbox("AaronA3@contoso.com");
        var folderCalendar = Folder.Bind(service, new FolderId(WellKnownFolderName.Calendar, testCalendar)); // <-- FAILS HERE

        var view = folderCalendar.FindItems(new ItemView(10));

这是我遇到的错误

<Trace Tag="EwsResponse" Tid="10" Time="2015-08-07 19:26:11Z" Version="15.00.0847.030">
  <?xml version="1.0" encoding="utf-8"?>
  <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
      <h:ServerVersionInfo MajorVersion="14" MinorVersion="1" MajorBuildNumber="218" MinorBuildNumber="6" Version="Exchange2010_SP
1" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/
types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
    </s:Header>
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <m:GetFolderResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsof
t.com/exchange/services/2006/types">
        <m:ResponseMessages>
          <m:GetFolderResponseMessage ResponseClass="Error">
            <m:MessageText>The specified folder could not be found in the store.</m:MessageText>
            <m:ResponseCode>ErrorFolderNotFound</m:ResponseCode>
            <m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
            <m:Folders />
          </m:GetFolderResponseMessage>
        </m:ResponseMessages>
      </m:GetFolderResponse>
    </s:Body>
  </s:Envelope>
</Trace>

这是我要访问的帐户

所以我的问题是 -- 我错过了什么?我是否错误地设置了角色分配?或者我需要在代码中做一些不同的事情吗?

在 Exchange 服务对象中有一个需要设置的 ImpersonatedUserId 属性。参见 this