EWS: Streaming Notifications and Exchange 2013 (and Office 365 Wave 15) No ratings yet.

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 ):

  1. Call Autodiscover for each mailbox requesting the ExternalEwsUrl and a new setting called “GroupingInformation” (mailbox1, mailbox2, mailbox3, etc.)
  2. Group the mailboxes by a concatenation of ExternalEwsUrl + GroupingInformation
  3. For each group (with ~ 200 mailboxes each)
    1. Create the ExchangeService object (so any cookie is sent in the following requests
    2. Add a header to this request called “X-AnchorMailbox” with a value set the SMTP address of the first mailbox in the group
    3. Add a header to this request called “X-PreferServerAffinity” with a value set to “true”
  4. Send a Subscribe request for each mailbox in this group to get a SubscriptionId (using ApplicationImpersonation)
  5. Send a GetStreamingEvents request with all the SubscriptionIds from the above step (not using ApplicationImpersonation)
  6. 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.


Please rate this

Leave a Reply

Your email address will not be published. Required fields are marked *