{"action":"created","issue":{"url":"https://api.github.com/repos/OfficeDev/ews-managed-api/issues/8","labels_url":"https://api.github.com/repos/OfficeDev/ews-managed-api/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/OfficeDev/ews-managed-api/issues/8/comments","events_url":"https://api.github.com/repos/OfficeDev/ews-managed-api/issues/8/events","html_url":"https://github.com/OfficeDev/ews-managed-api/issues/8","id":45304993,"number":8,"title":"StreamingSubscriptionConnection.IsOpen incorrectly reporting status","user":{"login":"axelitus","id":732441,"avatar_url":"https://avatars.githubusercontent.com/u/732441?v=3","gravatar_id":"","url":"https://api.github.com/users/axelitus","html_url":"https://github.com/axelitus","followers_url":"https://api.github.com/users/axelitus/followers","following_url":"https://api.github.com/users/axelitus/following{/other_user}","gists_url":"https://api.github.com/users/axelitus/gists{/gist_id}","starred_url":"https://api.github.com/users/axelitus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/axelitus/subscriptions","organizations_url":"https://api.github.com/users/axelitus/orgs","repos_url":"https://api.github.com/users/axelitus/repos","events_url":"https://api.github.com/users/axelitus/events{/privacy}","received_events_url":"https://api.github.com/users/axelitus/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/OfficeDev/ews-managed-api/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2014-10-08T22:22:44Z","updated_at":"2015-04-20T18:14:55Z","closed_at":null,"body":"I'm building a Library to handle Streaming Subscriptions at https://bitbucket.org/axelitus/axelitus.kvasir\r\n\r\nI'm doing some tests and when the Connection disconnects (due to reaching the lifetime limit) I re-open the connection but after that the IsOpen method returns false everytime even though I'm able to receive notifications through the subscription and the connection keeps disconnecting (when reaching the lifetime limit).\r\n\r\nFor the test I have a console application that loads a StreamListener that has a connection with lifetime set to 1 minute. I have a timer that asks for the connection status every 10 seconds. The StreamingSubscriptionConnection has a StreamConnection wrapper class that handles the automatic reconnection when timed out.\r\n\r\n![connection](https://cloud.githubusercontent.com/assets/732441/4568376/96bd8b98-4f39-11e4-930f-d3c0fb7109fb.jpg)"},"comment":{"url":"https://api.github.com/repos/OfficeDev/ews-managed-api/issues/comments/94528155","html_url":"https://github.com/OfficeDev/ews-managed-api/issues/8#issuecomment-94528155","issue_url":"https://api.github.com/repos/OfficeDev/ews-managed-api/issues/8","id":94528155,"user":{"login":"axelitus","id":732441,"avatar_url":"https://avatars.githubusercontent.com/u/732441?v=3","gravatar_id":"","url":"https://api.github.com/users/axelitus","html_url":"https://github.com/axelitus","followers_url":"https://api.github.com/users/axelitus/followers","following_url":"https://api.github.com/users/axelitus/following{/other_user}","gists_url":"https://api.github.com/users/axelitus/gists{/gist_id}","starred_url":"https://api.github.com/users/axelitus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/axelitus/subscriptions","organizations_url":"https://api.github.com/users/axelitus/orgs","repos_url":"https://api.github.com/users/axelitus/repos","events_url":"https://api.github.com/users/axelitus/events{/privacy}","received_events_url":"https://api.github.com/users/axelitus/received_events","type":"User","site_admin":false},"created_at":"2015-04-20T18:14:55Z","updated_at":"2015-04-20T18:14:55Z","body":"Hi... I could reproduce this behavior with the current code base.\r\n![streamlistenertest](https://cloud.githubusercontent.com/assets/732441/7236723/4bc86ee4-e75c-11e4-9723-d8abbc0f80d1.jpg)\r\nOn the picture you can see that while the program reports that the connection is not opened, the NewEmail event is correctly received.\r\n\r\nHere is the sample code (Command Line Application) to use the StreamListener wrapper for testing:\r\n```\r\nusing Axelitus.Kvasir.Exchange;\r\nusing Axelitus.Kvasir.Security;\r\nusing Microsoft.Exchange.WebServices.Data;\r\nusing System;\r\nusing System.Timers;\r\n\r\nnamespace TestSpace\r\n{\r\n    internal class Program\r\n    {\r\n        private static StreamListener sl;\r\n        private static string EWS_URL = @\"\";\r\n        private static string MAILBOX_USERNAME = @\"\";\r\n        private static string MAILBOX_PASSWORD = @\"\";\r\n\r\n        private static void Main(string[] args)\r\n        {\r\n            // Setup a timer\r\n            Timer tmr = new Timer(10000);\r\n            tmr.Elapsed += tmr_Elapsed;\r\n            // Manually setup the StreamListener\r\n            sl = new StreamListener(ExchangeVersion.Exchange2010_SP2,\r\n                EWS_URL, new SecureCredentials(MAILBOX_USERNAME, MAILBOX_PASSWORD));\r\n            // Manually setup StreamConnection\r\n            sl.StreamConnection = new StreamConnection(sl.Service, 1, true, true);\r\n            sl.StreamConnection.ItemPropertyBindings.Add(SerializablePropertyDefinition.Subject);\r\n            // Manually setup a subscription\r\n            StreamSubscription s = new StreamSubscription(new FolderId(WellKnownFolderName.Inbox), EventType.NewMail);\r\n            s.Subscribe(sl.Service);\r\n            sl.StreamConnection.AddSubscription(s);\r\n            // Register the StreamListener events\r\n            sl.Connected += sl_Connected;\r\n            sl.Disconnected += sl_Disconnected;\r\n            sl.NewEmail += sl_NewEmail;\r\n            Console.WriteLine(String.Format(\"Finished setting the StreamListener. Ready to start.\"));\r\n            Console.WriteLine(String.Format(\"{0} - StreamListener Started. Connection Lifetime: 1 minute.\", DateTime.Now.ToString(\"yyyy-MM-dd HH:mm:ss\")));\r\n            // Start the StreamListener and the Timer\r\n            sl.Start();\r\n            tmr.Start();\r\n            // Infinite loop to see what's happening\r\n            while (true)\r\n            {\r\n                if (Console.ReadKey().Key == ConsoleKey.Escape)\r\n                {\r\n                    break;\r\n                }\r\n            }\r\n\r\n            tmr.Stop();\r\n        }\r\n        // Triggered when a new email arrives to the subscribed email and folder.\r\n        static void sl_NewEmail(object sender, StreamNotificationEmailEventArgs e)\r\n        {\r\n            Console.WriteLine(String.Format(\"{0} - StreamListener NewEmail. Subject: {1}.\", DateTime.Now.ToString(\"yyyy-MM-dd HH:mm:ss\"), e.Email.Subject));\r\n        }\r\n        // Triggered when the StreamListener gets disconnected (usually when lifetime is reached).\r\n        static void sl_Disconnected(object sender, StreamConnectionEventArgs e)\r\n        {\r\n            Console.WriteLine(String.Format(\"{0} - StreamListener Disconnected.\", DateTime.Now.ToString(\"yyyy-MM-dd HH:mm:ss\")));\r\n        }\r\n        // Triggered when the StreamListener gets connected (usually after disconnected and with autoReconnect set to true).\r\n        static void sl_Connected(object sender, StreamConnectionEventArgs e)\r\n        {\r\n            Console.WriteLine(String.Format(\"{0} - StreamListener Connected.\", DateTime.Now.ToString(\"yyyy-MM-dd HH:mm:ss\")));\r\n        }\r\n        // Triggered when the laps time of the timer is reached.\r\n        static void tmr_Elapsed(object sender, ElapsedEventArgs e)\r\n        {\r\n            Console.WriteLine(String.Format(\"{0} - StreamListener.StreamConnection.IsOpen: {1}.\", DateTime.Now.ToString(\"yyyy-MM-dd HH:mm:ss\"), sl.StreamConnection.IsOpen));\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nJust change ```EWS_URL```, ```MAILBOX_USERNAME```, ```MAILBOX_PASSWORD``` for the correct values of a server you can test."}}