how to unsubscribe from EWS push notification using managed API
Asked Answered
C

2

6

I am using EWS managed API to do push subscription. Works fine

Now I want to unsubscribe

The managed API docs http://msdn.microsoft.com/en-us/library/office/dn458791(v=exchg.150).aspx say use service.EndSubscribeToPushNotifications. This is clearly wrong - this function is the pair of BeginSubscribeTo... async operation (reflector confirms this)

I see no obvious method on ExchangeService.

The general EWS docs http://msdn.microsoft.com/en-us/library/office/aa564263(v=exchg.150).aspx say send this XML, but that its only for pull operations

So what do I do?

Coycoyle answered 7/2, 2014 at 19:28 Comment(1)
Maybe you can improve the code formatting in the question and add a few more appropriate tags to reach more ppl. Tho I don't have a clue, question sounds interestingArdys
V
5

There doesn't seem to be a way to unsubscribe from push notifications. The only option is to let it time out.

From http://blogs.msdn.com/b/emeamsgdev/archive/2012/12/20/ews-push-notification-sample.aspx

The Unsubscribe button doesn't actually do anything currently, as Unsubscribe has not been implemented in the managed API. I will implement an Unsubscribe at some point, though it is not overly important as once the listener is closed, the subscription will timeout after a while when Exchange does not receive a response (or cannot connect) to the listener end-point.

BTW, the MSDN documentation recommends to use Streaming rather than push notifications:

From: Notification subscriptions, mailbox events, and EWS in Exchange

If you are using push notifications with Exchange 2010, consider upgrading your application to use streaming notifications, so that you don’t need a separate application to receive the events.

Update

Another source: Transitioning to Exchange Web Services Notifications

We are also often asked how push notifications timeouts work. Suppose your client subscribed to push notifications, and then unexpectedly goes offline. The server will not be able to push out the next set of events as notifications to the client (or, more importantly, the server will not get a response to its notifications message). Rather than give up right away, the server will retry to push them out up to three times. After the first failure, the server will wait the timeout amount of time (that’s the timeout that you set in the subscription request) and try again. If that attempt fails, the server will wait twice the timeout time and try again. If that fails, the server will wait three times the timeout time and try again. Finally, if the third retry attempt fails, the server will give up and delete the subscription.

Update 2

Outside of the managed API it looks like you can terminate the subscription by returning Unsubscribe in the SubscriptionStatus element instead of OK.

In summary, there are really two ways to end a subscription on a CAS:

  1. You can send “Unsubscribe” in the response message (as a response to a notifications message from the CAS).
  2. You can become unresponsive to notifications messages.

We recommend the first method (sending an unsubscribe message) rather than the second method, which causes the Client Access server to perform unnecessary work.

MSDN: SubscriptionStatus

Code Sample (with SubscriptionStatus.OK, so you have to set it to Unsubscribe to get the desired effect): Exchange Web Services .NET > Tutorial > Push event notification

Valentinavalentine answered 10/2, 2014 at 19:49 Comment(3)
cant use streaming notifications cos it is too resource intensive (lots of TCP connections idling) and I have a nice big server app anywayCoycoyle
the first thing you note is actually repeating my point: The managed EWS api doesn't have an unsubscribe method. The doesn't necessarily mean that you can do it. BTW if i don't get a better answer then u win cos you found the stuff about timeoutCoycoyle
Yes, no unsub for PUSH notifications, only for PULL. BTW, I don't think streaming notifications are that intensive, since you can receive notifications for multiple MBs on a single connection. With PUSH, you have these short TCP sessions being initiated for each MB's notifications, so it's debatable which is more efficient.Birdcage
S
1

The update2 by diegog does work, i.e., if we send the response with the unsubscribe status the exchange unsubscribe the push notification and you don't receive any further notification thereafter.

The only issue with it is that it unsubscribe all the subscription, i.e., in case you have multiple subscription, then the response with the status unsubscribe would make the exchange unsubscribe all the subscription.

Skite answered 5/7, 2016 at 13:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.