我在生产中遇到此错误。不知道究竟是什么原因造成的。
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)
{ }
}