【发布时间】:2011-08-20 04:38:38
【问题描述】:
我正在使用 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。
【问题讨论】:
标签: c# exchangewebservices exchange-server-2010