简体   繁体   中英

Exchange 2010 and Application Impersonation Issue

I am trying to setup Application Impersonation in Exchange 2010 to allow a .NET application the ability to read/update my organization's calendars.

So far, I have created a service account and a Role Assignment

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

However, when I go to actually access the calendar of an account, I get an ErrorFolderNotFound

Here is the code that I am using for the test

        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));

Here is the error that I am getting

<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>

Here is the account I am trying to access 在此处输入图片说明

So my question is -- what am I missing? Did I setup the Role assignment incorrectly? Or do I need to do something different in the code?

In the Exchange Service object there is an ImpersonatedUserId property that needs to be set. See this .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM