我的流媒体订阅去哪儿了?

发布于 2024-11-05 11:30:55 字数 1725 浏览 0 评论 0原文

我正在使用 Microsoft Exchange Web Services 1.1 SDK 并使用流连接来订阅新邮件通知。接收通知一切正常,但我偶尔会收到有关我的 Exchange 无法找到我的订阅的错误。

下面是我用来初始化我的订阅和我使用的事件的代码。

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 - 您必须至少向此连接添加一个订阅,然后才能打开它。

该异常不言而喻,我知道我可以简单地在 Reconnect() 内创建另一个订阅。我希望有人能帮助我了解订阅的去向。我无法想象像 Exchange 2010 这样的产品会简单地失去我的订阅。另外,我无法指出错误。有时我可以使订阅保持有效 10 分钟,而有时我会在 2-3 分钟后收到有关我的订阅无效的错误。

就其价值而言,我使用的是 Exchange 2010 SP1。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小梨窩很甜 2024-11-12 11:30:55

从 Reflector 中的源代码来看,似乎可以删除订阅的唯一两种方法(除了处理 StreamingSubscriptionConnection 之外,是通过调用删除,我假设您没有这样做,或者通过订阅返回除 ServiceError.ErrorMissedNotificationEvents 之外的错误代码。您可以通过查看 ResolveError 中的 errorEventArgs.Exception 来检查错误。如果它是 ServiceResponseException 的实例,则将其转换为该类型并获取 ErrorCode 属性。然后,订阅会自动删除。

获取错误代码可能会帮助您找出发生这种情况的原因,但即使您无法修复它,您也可以确定何时删除该订阅,并在这种情况下异步添加另一个订阅。

From looking at the source in Reflector, it looks like the only two ways a subscription could be removed (aside from disposing the StreamingSubscriptionConnection, is by calling Remove, which I assume you aren't doing, or by a subscription returning an error code other than ServiceError.ErrorMissedNotificationEvents. You can inspect the error by looking at errorEventArgs.Exception in your ResolveError handler. If it is an instance of ServiceResponseException, cast it to that type and get the ErrorCode property. After firing off the OnSubscriptionError event, the subscription is then removed automatically.

Getting the error code might help you track down why this is happening, but even if you can't fix it, you can determine when the subscription will be removed and asynchronously add in another subscription in that case.

一直在等你来 2024-11-12 11:30:55

我知道很久以前就有人问过这个问题,但我想我会发布我如何解决该错误(找不到任何可以解释为什么会发生这种情况的内容)。顺便说一下,还使用 ​​Office 2010 sp1。

您可以使用发送者的 Count() 方法来验证您是否有有效的订阅;

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
        }
    }

I know this was asked a long time ago but i thought i would post how im getting around the error (cant find anything that explains WHY it happens). Also using office 2010 sp1 by the way.

You can use the Count() method from sender to verify 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
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文