gpt4 book ai didi

exchange-server - 什么导致 OnSubscriptionError 在 EWS API 的 StreamingSubscriptionConnection 中被触发?

转载 作者:行者123 更新时间:2023-12-04 18:09:58 26 4
gpt4 key购买 nike

我在生产中遇到此错误。不知 Prop 体是什么原因造成的。

OnSubscriptionError : 
Microsoft.Exchange.WebServices.Data.ServiceResponseException:
The specified subscription was not found.

现在我想模拟我的 中的行为开发环境 .
  • 我已订阅事件 Connection.OnSubscriptionError我的事件处理程序是 OnSubscriptionError .现在我想测试处理程序。为此,我想要某种方式来触发我遇到麻烦的那个事件。
  • 我曾尝试在应用程序运行时关闭交换主机服务,但这不会触发 OnsubscriptionError Event .
  • 我想知道以下代码在 OnsubscriptionError event 时是否有效被解雇。或者我必须在创建连接之前重新创建订阅对象。

  • 这是示例代码:
    Subscription =_exchangeService.SubscribeToStreamingNotifications(
    new FolderId[] { WellKnownFolderName.Inbox },
    EventType.NewMail);
    CreateStreamingSubscription(_exchangeService, Subscription);

    private void CreateStreamingSubscription(ExchangeService service,
    StreamingSubscription subscription)
    {

    // public StreamingSubscriptionConnection(ExchangeService service, int lifetime) lifetime is in minutes and 30 mins is the maximum time till which
    // the connection can be open.
    Connection = new StreamingSubscriptionConnection(service, 30);
    Connection.AddSubscription(subscription);
    Connection.OnNotificationEvent += OnNotificationEvent;
    Connection.OnSubscriptionError += OnSubscriptionError;
    Connection.OnDisconnect += OnDisconnect;
    Connection.Open();
    }
    private void OnSubscriptionError(object sender, SubscriptionErrorEventArgs args)
    {
    if (args.Exception is ServiceResponseException)
    {
    var exception = args.Exception as ServiceResponseException;
    }
    else if (args.Exception !=null)
    {
    Logwriter.LogMsg(_clientInfo.LogId, LogLevel.FATAL,
    "OnSubscriptionError() : " + args.Exception.Message +
    " Stack Trace : " + args.Exception.StackTrace +
    " Inner Exception : " + args.Exception.InnerException);
    }
    try
    {
    Connection = (StreamingSubscriptionConnection)sender;
    if(!Connection.IsOpen)
    Connection.Open();
    }
    catch (ServiceResponseException exception)
    { }
    catch (Exception ex)
    { }
    }

    最佳答案

    我和你一样实现了一个类似的机制,但没有调用 Connection.Open();您需要重新启动整个订阅...因为正如我上面的@BraveHeart 所说,一次 OnSubscriptionError发生您无法重新打开连接...

    这是您可以使用的代码片段

    private void OnSubscriptionError(object sender, SubscriptionErrorEventArgs args)
    {
    connection = (StreamingSubscriptionConnection)sender;
    //Log here
    if (args.Subscription != null)
    {
    try
    {
    connection.RemoveSubscription(args.Subscription);
    }
    catch (Exception removeSubscriptionException)
    {
    //Log Here
    }
    }
    if (connection != null && connection.IsOpen)
    {
    try
    {
    connection.Close();
    }
    catch (Exception subscriptionCloseException)
    {
    //Log Here
    }
    }
    Subscription =_exchangeService.SubscribeToStreamingNotifications(
    new FolderId[] { WellKnownFolderName.Inbox },EventType.NewMail);
    CreateStreamingSubscription(_exchangeService, Subscription);
    }

    关于exchange-server - 什么导致 OnSubscriptionError 在 EWS API 的 StreamingSubscriptionConnection 中被触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16579638/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com