Exchange 2013 (edit)
Exchange 2013 introduced a new affinity model which means that streaming subscriptions to multiple mailboxes need to be handled in a different way to earlier versions. If you are connecting to a single mailbox, you shouldn’t have a problem, but you most likely will encounter issues if you are connecting to many mailboxes. Additionally, the EWS managed API has not yet been updated with the changes, so quite a lot of the process needs to be implemented manually.
The steps needed to connect and monitor multiple mailboxes are as follows (please see http://msdn.microsoft.com/en-us/library/office/dn458789(v=exchg.150).aspx ):
- Call Autodiscover for each mailbox requesting the ExternalEwsUrl and a new setting called “GroupingInformation” (mailbox1, mailbox2, mailbox3, etc.)
- Group the mailboxes by a concatenation of ExternalEwsUrl + GroupingInformation
- For each group (with ~ 200 mailboxes each)
- Create the ExchangeService object (so any cookie is sent in the following requests
- Add a header to this request called “X-AnchorMailbox” with a value set the SMTP address of the first mailbox in the group
- Add a header to this request called “X-PreferServerAffinity” with a value set to “true”
- Send a Subscribe request for each mailbox in this group to get a SubscriptionId (using ApplicationImpersonation)
- Send a GetStreamingEvents request with all the SubscriptionIds from the above step (not using ApplicationImpersonation)
- Pass events returned by GetStreamingEvents or GetEvents to a separate thread for processing
I have published a code sample to Codeplex (http://ewsstreaming.codeplex.com/) that implements the above logic using the EWS Managed API. For further updates, please follow the Codeplex pages – they will be updated as the sample is improved.
EWS Streaming Notification Sample
This project demonstrates how to handle streaming notifications specifically for Wave 15 of Office 365 (and also Exchange 2013 on-premises installations). The code has recently been rewritten completely to simplify the grouping logic and add some error handling (disconnect events are handled properly, though currently subscription errors are not handled).
Sample application demonstrating how to create a daemon application that interacts with EXO using EWS
An old code sample illustrating the use of SimpleMAPI
Async & Await
The async/await keywords