Pergunta

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?

Foi útil?

Solução

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

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top