Search code examples
exchangewebservices

EWS: Closing StreamingSubscriptionConnection after it get expired and reopened raises an exception


I have created an object of StreamingSubscriptionConnection that has a lifetime of 30 minutes , which is the max, and reopens automatically as suggested in Auto Reconnect When Using StreamingSubscriptionConnection in EWS.
Till this point everything works fine. however, after the first auto reconnect, if I would like to close the connection to add a new subscription, exceptions start to raise when I open the connection again saying "there is another connection open against the subscription" Does anyone have any idea about how this happen, and how to solve it


Solution

  • Funny that your question came in today when I am knee-deep in this exact same area in my app! My understanding of this, after some back and forth with the folks in Exchange support, is that you can only add new subscriptions (or remove ones you don't want any more) in the OnDisconnect event handler. I have tried steps similar to yours and get the same kind of errors if I do it outside the handler. As I need for my app to add new subscriptions relatively promptly, I am tending toward a shorter timeout on my streaming connection (e.g. 3 mins), which I realize will add overhead for the more frequent TCP session establishments. In the long run, I'm not sure how bad this is, as under the covers streaming notifications are just doing long polling, so if you're getting lots of notifications, I think you have lots of HTTP Req/Rsp sequences anyway.

    In concept Streaming Notifications are great, but based on the doc so far. i.e. the various blogs and forums like this, and the almost useless MSDN references, I have this sinking feeling that I am off on a rather unpleasant adventure I was not expecting.