我正在尝试使用 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);
}
}
}
}
如果有帮助,我附上了错误的屏幕截图: