EWS - 委托访问

时间:2013-09-20 07:37:46

标签: c# calendar exchange-server exchangewebservices exchange-server-2010

我正在尝试使用EWS访问其他人日历。我可以访问我自己的日历:

    foreach (Appointment appointment in service.FindItems(
        WellKnownFolderName.Calendar, new ItemView(int.MaxValue)))
    {
        Console.WriteLine(appointment.Subject);
    }
}

然而,当我尝试冒充(即使使用委托访问)时,我得到一个未处理的异常错误,使用下面的代码(对不起它的完整代码,但认为它的简短可能有帮助!)问题孩子似乎在foreach环

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Exchange.WebServices.Data;
using Test.ExchangeServices;
 using System.Net;

namespace Test
{
class Program
{
    static void Main(string[] args)
    {
 // Connect to Exchange Web Services
    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);

    service.Credentials = new WebCredentials("User", "Pass", "Domain");
    service.Url = new Uri("https://EWS/EWS/Exchange.asmx");

    //Impersonate the user who is creating the appiontment request (doesn't work so commented out)
// service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, userEmail);

/Delegate access 

    foreach (Appointment appointment in service.FindItems(
new FolderId(WellKnownFolderName.Calendar, new Mailbox("otheremployee@company.com")), 
new ItemView(10)))
    {
        Console.WriteLine(appointment.Subject);
    }
}



    }
}

如果有帮助,我附上了错误的屏幕截图:

http://i44.tinypic.com/nh1jdi.png

1 个答案:

答案 0 :(得分:1)

您需要审阅者访问日历,然后才能使用。 :)