Where is my streaming subscription going?

I use the Microsoft Exchange Web Services 1.1 SDK and use a streaming connection to sign up for a new email notification. Everything works fine for receiving notifications, but I get errors from time to time that my Exchange could not find my subscription.

Below is the code that I use to initialize my subscription and the events I use.

public void Subscribe() { var locateMailbox = new Mailbox { Address = "myemail" }; var folderId = new FolderId(WellKnownFolderName.Inbox, locateMailbox); var foldersToWatch = new[] {folderId}; StreamingSubscription streamingSubscription = _exchangeService.SubscribeToStreamingNotifications(foldersToWatch, EventType.NewMail); // Timeout is set at 1 minute intentionally var streamingConnection = new StreamingSubscriptionConnection(_exchangeService, 1); streamingConnection.AddSubscription(streamingSubscription); streamingConnection.OnSubscriptionError += ResolveError; streamingConnection.OnDisconnect += Reconnect; streamingConnection.Open(); } public void Reconnect(object sender, SubscriptionErrorEventArgs disconnectEventArgs) { if (!((StreamingSubscriptionConnection)sender).IsOpen) ((StreamingSubscriptionConnection)sender).Open(); } public void ResolveError(object sender, SubscriptionErrorEventArgs errorEventArgs) { var streamingSubscriptionConnection = (StreamingSubscriptionConnection) sender; if (!streamingSubscriptionConnection.IsOpen) streamingSubscriptionConnection.Open(); } 

ServiceLocalException - You must add at least one subscription to this connection before it can be opened.

This exception speaks for itself, and I know that I can just create another subscription inside Reconnect() . I hope someone can help me figure out where the subscription goes. I can’t imagine that a product like Exchange 2010 will simply lose my subscription. In addition, I cannot indicate an error. Sometimes I can keep my subscription active for 10 minutes, and sometimes I get a message that my subscription is not valid after 2-3 minutes.

Why use Exchange 2010 SP1.

+6
source share
2 answers

From a look at the source in Reflector, it looks like there are only two ways in which a subscription can be removed (except for the utilization of StreamingSubscriptionConnection , it is called β€œDelete”, which I suppose you do not, or by returning an error code different from ServiceError.ErrorMissedNotificationEvents You can check this error by looking at errorEventArgs.Exception in your ResolveError handler. If it is an instance of ServiceResponseException , apply it to this type and get the ErrorCode property. After the OnSubscriptionError event is OnSubscriptionError subscription is then automatically deleted.

Getting the error code will help you keep track of why this is happening, but even if you cannot fix it, you can determine when the subscription will be deleted and asynchronously add to another subscription in this case.

+7
source

I know that this was asked a long time ago, but I thought that I would publish how to get around the error (I can not find anything that explains why this is happening). Also using office 2010 sp1, by the way.

You can use the Count () method from the sender to check if you have an active subscription;

 private static void onDisconnect(object sender, SubscriptionErrorEventArgs args) { StreamingSubscriptionConnection renew = (StreamingSubscriptionConnection)sender; if(renew.CurrentSubscriptions.Count() > 0){ //if subscription exists reopen as normal renew.Open(); } else { //recreate the whole connection } } 
+1
source

Source: https://habr.com/ru/post/887444/


All Articles