2014-01-06 50 views
1

我们通过交换管理我们的汽车游泳池的预订。每辆汽车都有一台压光机,您可以在该压光机上插入与汽车的约会,因为您想要使用它。如何从EWS检索公共日历?

我的任务是检索每辆汽车的日历和每个约会,但我坚持如何通过EWS进行正确的呼叫。

我的步骤如下:

  • 创建Exchange服务的服务帐户的
  • 使用凭证
  • AutodiscoverUrl()
  • 创建CalenderFolder,CalenderView UND检索约会。

现在我的问题位于“检索约会”,因为我只能用WellKnownFolders访问我自己的日历。

我怎样才能访问其他公共calanders并检索他们的约会?

这是我与迄今使用的代码:(从http://msdn.microsoft.com/en-us/library/office/dn439786(v=exchg.80).aspx聚集)

ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack; 

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1); 
service.Credentials = new WebCredentials(@"domain\svc_account", @"Dummypassword"); 
service.UseDefaultCredentials = false; 
service.TraceEnabled = true; 
service.TraceFlags = TraceFlags.All; 
service.AutodiscoverUrl(@"[email protected]", RedirectionUrlValidationCallback); 

DateTime startTime = DateTime.Now; 
DateTime endTime = DateTime.Now.AddDays(10); 
int num_appts = 10; 

CalendarFolder calFolder = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet()); 
CalendarView calView = new CalendarView(startTime, endTime, 10); 
calView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End); 

FindItemsResults<Appointment> appointments = calFolder.FindAppointments(calView); 

foreach (Appointment a in appointments) 
{ 
    //Do stuff later on... 
} 

还是那句话:这非常适用于在我的压延约会。我无法在MSDN中找到有关如何访问其他人数据的部分。

回答

3

看一看Exchange Impersonation

您可以让一个特定的用户帐户冒充另一个用户帐户并访问他们的详细信息,而不需要他们的用户名和密码。这应该也适用于资源日历。

string impName = @"impy"; 
string impPassword = @"password"; 
string impDomain = @"domain"; 
string impEmail = @"[email protected]"; 

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010); 
service.Credentials = new NetworkCredential(impName, impPassword, impDomain); 
service.AutodiscoverUrl(impEmail); 

// This will work as if you are that car. 
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, @"[email protected]"); 

更多的参考资料: http://msdn.microsoft.com/en-us/library/dd633680(v=exchg.80).aspx

+1

我确认你的答案,但我需要等到管理员为服务帐户提供适当的权限才能以用户身份进行模拟。 – Marco

2

鉴于该服务用户已经读访问给定用户的日历,你可以做这样的事情:

// this is the user whose calendar you want to access 
var emailAddress = "[email protected]"; 

var mailbox = new Mailbox(emailAddress); 
var folderId = new FolderId(WellKnownFolderName.Calendar, mailbox); 
var calendar = CalendarFolder.Bind(service, 
            folderId, 
            BasePropertySet.FirstClassProperties); 
+1

我一直遇到“指定的文件夹不存在”。我仍在调查。此技术是否也需要启用模拟功能? – ziddarth