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

  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 ( 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 Application

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

Azure Cloud

Async & Await

The async/await keywords

ASP.NET Web API + Ajax Sync and Ajax Async

Secure Password

Auto Tasks