EWS: Streaming Notifications and Exchange 2013 (and Office 365 Wave 15)


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.

Comments (4)

  1. Thanks for the valuable information

  2. Excellent info!!!!

  3. Madhu says:

    I want code for grabbing emails from office 365 using streaming notifications with EWS managed API

  4. vinayakmshanbhag@gmail.com says:

    In on premise 2013 setup I have 2 CAS server & 2 Mailbox server; I created one test mailbox on one & another on other mailbox server, AutoDiscover always returns same ExternalEWSUrl & GroupInformation. When I am trying to Stream notification I run into following error,

    "One or more subscriptions in the request reside on another Client Access server. GetStreamingEvents won't proxy in the event of a batch request"

    Also I noticed 2013 never returns Backend-Override-Cookie. How to Solve this issue. Please help.

Skip to main content