2014-01-06 72 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