在使同步流式通知正常工作後,我發現異步BeginSubscribeToStreamingNotifications()
。使用EWS BeginSubscribeToStreamingNotifications
用這個擺弄了一下之後,使用了非常有限的文檔,我放棄了。我根本無法得到這個工作。
環境
這是一些相關的代碼。我正在啓動我的服務,連接並調用BeginSubscribeToStreamingNotifications()
方法。
public static void InitSubscriptions()
{
var service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
service.Credentials = new NetworkCredential("some", "login", "here");
service.Url = new Uri("https://some.exchange/server");
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "[email protected]");
// Initiating the subscription
var subscription = service.BeginSubscribeToStreamingNotifications(new AsyncCallback(Callback), null, new FolderId[] { WellKnownFolderName.Inbox }, EventType.NewMail);
}
private static void Callback(IAsyncResult result)
{
// ???
}
正如你所看到的,我不知道在回調方法中該做什麼。
問題
我不知道如何實際訂閱使用此方法的通知。我使它同步工作,但如果可能的話,我想使它異步工作
下面是按預期工作的同步示例。
public static void InitSubscriptions()
{
var service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
service.Credentials = new NetworkCredential("some", "login", "here");
service.Url = new Uri("https://some.exchange/server");
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "[email protected]");
// Initiating the subscription
var subscription = service.SubscribeToStreamingNotifications(new FolderId[] { WellKnownFolderName.Inbox }, EventType.NewMail);
var connection = new StreamingSubscriptionConnection(service, 30);
connection.AddSubscription(subscription);
// Delegate handlers
connection.OnNotificationEvent += new StreamingSubscriptionConnection.NotificationEventDelegate(SomeMethod);
connection.OnSubscriptionError += new StreamingSubscriptionConnection.SubscriptionErrorDelegate(SomeErrorMethod);
connection.OnDisconnect += new StreamingSubscriptionConnection.SubscriptionErrorDelegate(SomeDisconnectMethod);
}
所以我的問題是:我如何將同步流訂閱轉換爲異步流訂閱?