Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Exchange server 一段时间后未收到EWS流通知_Exchange Server_Exchangewebservices_Office365api - Fatal编程技术网

Exchange server 一段时间后未收到EWS流通知

Exchange server 一段时间后未收到EWS流通知,exchange-server,exchangewebservices,office365api,Exchange Server,Exchangewebservices,Office365api,我对EWS中的流媒体事件有一个奇怪的问题 我已使用此处提到的所需Cookie订阅了一组邮箱: 在收到通知一段时间后,他们突然停下来(通常在40分钟-1小时后) 我试着用EWS跟踪调试它,发现“心跳”消息 不再接收exchange server定期发送的邮件,例如: <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <soap11:Header xmlns:soap11="http://schemas.xm

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

我已使用此处提到的所需Cookie订阅了一组邮箱:

在收到通知一段时间后,他们突然停下来(通常在40分钟-1小时后) 我试着用EWS跟踪调试它,发现“心跳”消息 不再接收exchange server定期发送的邮件,例如:

<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>

StreamingSubscriptionConnection的生存期为1-30,因此在生存期结束后,最小流打开连接,引发事件并关闭连接

你找到解决问题的方法了吗?在我调查了这个问题之后-看起来微软不时会失去订阅(至少推送方法就是这样),所以我的解决方案是为hearbeat消息设置一个拦截器,然后,如果在某个时间间隔内没有消息,则使用非流式版本的通知会观察到重新订阅名称问题。心跳会在一段时间后停止,或者在触发另一个事件时停止。真是笨手笨脚。sborpo的解决方案似乎是唯一的出路
`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");
}`