[Exchange-Online][EWS][C#][Windows version] EWS streaming notifications are not received after some time RRS feed

  • Question

  • I have a strange problem with the streaming events in EWS.

    I have subscribed to a group of mailboxes using the needed cookies as mentioned here:

    After receiving notifications for some time, suddenly they stop to arrive ( usually after 40 minutes - 1 hour) I tried to debug it with the EWS trace and noticed that "heartbeat" messages that the exchange server sends periodically are no longer received, and example to this message:

    <Envelope xmlns="">
    <soap11:Header xmlns:soap11="">
      <ServerVersionInfo xmlns:xsd="" xmlns:xsi="" MajorVersion="15" MinorVersion="1" MajorBuildNumber="1178" MinorBuildNumber="21" Version="V2017_04_14" xmlns="" />
    <soap11:Body xmlns:soap11="">
      <m:GetStreamingEventsResponse xmlns:xsd="" xmlns:xsi="" xmlns:t="" xmlns:m="">
          <m:GetStreamingEventsResponseMessage ResponseClass="Success">

    I have set the OnDisconnect event to re-open the connection on timeout and saw that it works - so i guess its not a timeout problem.

    Have anybody have a clue why the messages stop to arrive ?

    Is the subscription is lost? should i re-subscribe ? (I didn't find any reference to this issue)

    this is my code:

    static void ListenerFunciton()
    // Set the exchange service
    ExchangeService service = null;
    service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
    service.Url = new Uri("");
    service.Credentials = new WebCredentials(ServiceAccount, ServicePassowrd);
    System.Net.ServicePointManager.ServerCertificateValidationCallback =
     delegate (Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
         return true;
     string anchorMailbox = ""
     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.OnNotificationEvent += OnNotificationEvent;
     connection.OnDisconnect += OnDisconnect;
    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;
    static private  void OnNotificationEvent(object sender, NotificationEventArgs args)
        file.WriteLine(DateTime.Now.ToString() + " || Got notification");
        foreach (NotificationEvent notification in args.Events)
            file.WriteLine("From Subscription: "+args.Subscription.Id+" Event: "+notification.EventType.ToString("D"));

    Monday, June 19, 2017 2:41 PM