Question

I'm using the Microsoft Exchange Web Services 1.1 SDK and using the streaming connection to subscribe to new mail notification. All works fine for receiving the notifications but I receive errors every once in a while about my Exchange not being able to find my subscription.

Below is the code I'm using 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.

That exception speaks for itself and I'm aware that I can simply create another subscription inside of Reconnect(). I'm hoping someone can help me understand where the subscription is going. I can't imagine a product such as Exchange 2010 would simply lose my subscription. Also, I can't pin point the error. Sometimes I can keep my subscription active for 10 minutes and other times I receive an error about my subscription not being valid after 2-3 minutes.

For what it's worth I'm using Exchange 2010 SP1.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top