2013-10-10 73 views
4

這可能是一個非常基本的問題,但我還沒有找到任何答案。我在Windows服務中使用Exchange Web服務來監控發送到我們的Exchange 2010服務器的新郵件,並使用訂閱服務。它工作得很好,很花哨,但問題在於服務器不可用(例如停電後),然後訂閱超時,Windows服務需要重新啓動。有沒有辦法在超時後更新訂閱,或者拉動EvenType.Status事件?EWS - 超時後續訂訂閱嗎?

這裏是我到目前爲止的代碼:

ExchangeService service; 
    PullSubscription subscriptionInbox; 

    private void SetService() 
    { 
     service = new ExchangeService(ExchangeVersion.Exchange2010); 
     service.Url = new Uri("myurl"); 
     service.Credentials = new WebCredentials(emailAddress, pass); 
    } 

    private void SetSubscription() 
    { 
     if (service == null) 
     { 
      SetService(); 
     } 

     subscriptionInbox = service.SubscribeToPullNotifications(
     new FolderId[] { WellKnownFolderName.Inbox }, 
     5, 
     null, 
     EventType.NewMail, EventType.Modified); 
    } 

    private void DoStuff(object sender, EventArgs e) 
    { 
     GetEventsResults eventsInbox = subscriptionInbox.GetEvents(); 
     EmailMessage message; 

     foreach (ItemEvent itemEvent in eventsInbox.ItemEvents) 
     { 
      //Do Stuff 
     } 
    } 

任何想法,我可以怎麼用這個去?

回答

2

當您失去訂閱時,最好創建一個新訂閱 - 而不是嘗試恢復臨時數據。您可以使用舊水印重新訂閱,但成本過高。此鏈接提供了一些關於恢復與丟失訂閱有關的通知的附加上下文:http://msdn.microsoft.com/en-us/library/office/dn458788(v=exchg.150).aspx#bk_recover。您可能還想查看此頻道9視頻,其中討論了從丟失的訂閱中恢復:http://channel9.msdn.com/Events/Open-Specifications-Plugfests/Windows-Identity-and-Exchange-Protocols-Plugfest-2012/Exchange-Web-Services-Best-Practices-Part-2