gpt4 book ai didi

exchange-server - 一段时间后未收到 EWS 流式传输通知

转载 作者:行者123 更新时间:2023-12-04 06:53:39 25 4
gpt4 key购买 nike

我对 EWS 中的流媒体事件有一个奇怪的问题。

我已经使用此处提到的所需 cookie 订阅了一组邮箱: https://msdn.microsoft.com/en-us/library/office/dn458789(v=exchg.150).aspx

在收到通知一段时间后,他们突然停止到达(通常在 40 分钟 - 1 小时后)我尝试使用 EWS 跟踪对其进行调试,并注意到“心跳”消息不再收到交换服务器定期发送的消息,此消息的示例:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<soap11:Header xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/">
<ServerVersionInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" MajorVersion="15" MinorVersion="1" MajorBuildNumber="1178" MinorBuildNumber="21" Version="V2017_04_14" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" />
</soap11:Header>
<soap11:Body xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/">
<m:GetStreamingEventsResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
<m:ResponseMessages>
<m:GetStreamingEventsResponseMessage ResponseClass="Success">
<m:ResponseCode>NoError</m:ResponseCode>
<m:ConnectionStatus>OK</m:ConnectionStatus>
</m:GetStreamingEventsResponseMessage>
</m:ResponseMessages>
</m:GetStreamingEventsResponse>
</soap11:Body>

我已将 OnDisconnect 事件设置为在超时时重新打开连接并看到它有效 - 所以我猜这不是超时问题。

有没有人知道为什么消息停止到达?

订阅丢失了吗?我应该重新订阅吗?(我没有找到任何关于这个问题的引用)

这是我的代码:

`static void ListenerFunciton()
{
// Set the exchange service
ExchangeService service = null;
service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
service.Credentials = new WebCredentials(ServiceAccount, ServicePassowrd);
System.Net.ServicePointManager.ServerCertificateValidationCallback =
delegate (Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
return true;
};

string anchorMailbox = "blabla@domain.onmicrosoft.com"
StreamingSubscription subsribption = null;

//Set the coockies
service.HttpHeaders.Add("X-AnchorMailbox", anchorMailbox);
service.HttpHeaders.Add("X-PreferServerAffinity", "true");

// Set the impersonation
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, anchorMailbox);

subsribption = service.SubscribeToStreamingNotifications(new FolderId[] { WellKnownFolderName.Inbox }, EventType.NewMail);

int index = service.HttpResponseHeaders["Set-Cookie"].IndexOf("X-BackEndOverrideCookie");
string coockie = service.HttpResponseHeaders["Set-Cookie"].Substring(index).Split(';')[0];
service.HttpHeaders.Add("Cookie", coockie);

StreamingSubscriptionConnection connection = new StreamingSubscriptionConnection(service, 29);
connection.AddSubscription(subsribption);
connection.OnNotificationEvent += OnNotificationEvent;
connection.OnDisconnect += OnDisconnect;
connection.Open();
while(true)
{

}

}

static private void OnDisconnect(object sender, SubscriptionErrorEventArgs args)
{
Console.WriteLine("\n\n\n\nFrom now this is the reconnection\n\n\n\n");
//cast the sender object
StreamingSubscriptionConnection connection = (StreamingSubscriptionConnection)sender;
//reconnect
connection.Open();

}

static private void OnNotificationEvent(object sender, NotificationEventArgs args)
{
file.WriteLine(DateTime.Now.ToString() + " || Got notification");
file.Flush();
foreach (NotificationEvent notification in args.Events)
{
file.WriteLine("From Subscription: "+args.Subscription.Id+" Event: "+notification.EventType.ToString("D"));
file.Flush();
}
file.WriteLine("\n\n");
}`

最佳答案

StreamingSubscriptionConnection 的生命周期为 1-30,因此在生命周期最小后 Stream 打开连接、引发事件并关闭连接。

关于exchange-server - 一段时间后未收到 EWS 流式传输通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44613198/

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