我正在使用 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 - You must add at least one subscription to this connection before it can be opened.
这个例外不言自明,我知道我可以简单地在Reconnect()
. 我希望有人可以帮助我了解订阅的去向。我无法想象像 Exchange 2010 这样的产品会简单地失去我的订阅。另外,我无法指出错误。有时我可以让我的订阅保持 10 分钟有效,有时我会在 2-3 分钟后收到关于我的订阅无效的错误。
值得我使用的是 Exchange 2010 SP1。