EWS Online sample for using streaming notifications with impersonation RRS feed

  • Question

  • Hi,

    I am looking for a good sample to use streaming notifications with an impersonate scenario to Exchange Online. There is a lot of information available, but I miss some pieces.

    Basically, I am creating an application which logs in to Exchange Online with the impersonation account. When a user logs into the application, a new streaming notification will be created to his/her own mailbox. Events will be trapped to process the notifications per user.

    I suspect I have to create a pool of Exchange connections to enable this, but I really would like to just use one ExchangeService object. I read somewhere that you can switch the property "ImpersonatedUserId" (which is the mailbox to which you want to subscribe to) on an open connection, but I'm not clear on the workings of this.

    Also, I noticed you can create FolderId's with the Microsoft.Exchange.WebServices.Data.FolderId with a well known folder name AND mailbox as parameters. Does this mean you can create a StreamingSubscription object with several folderId's targeting different mailboxes?

    Anyway, just a code sample would do as well I guess...:)



    Thursday, April 18, 2013 7:39 AM


All replies

  • If you going to use multiple Streaming subscription the first thing you want to make sure you do is set the ServicePointManager.DefaultConnectionLimit to more the 2 (which is the default)

    With Impersonation your going to need a different ExchangeService object per Mailbox your impersonating as on the server "the connection remains open to allow the server to push notifications back to your application" as per While switching the "ImpersonatedUserId" is possible I don't think it will work as you would be changing the credentials on the active subscription\connection and that can't be good for number of reasons.

    Subscription don't span mailboxes you need a seperate subscription for every Mailbox you want to subscribe to (else you will get a "A subscription can only be established on a single public folder or on folders from a single mailbox." error)


    • Marked as answer by Ruud_NL Friday, May 3, 2013 2:23 PM
    Friday, April 19, 2013 11:48 AM
  • Hi Glen,

    Thanks for the answer! I decided to make use of a static list which stores SignalR connections, their email address and the EWS Service for that email address, streaming connection and subscription object. With that, I can close it neatly if a client session is disconnected.

    I do get EWS errors now and then, probably because of the thresholds, so I think creating a service with pull subscriptions would offer the best in control and stability (with streaming/push notifications, only thing you can do is hope and wait that EWS sends events back).

    Thanks again, really helpful!


    Friday, May 3, 2013 2:27 PM