public void FetchNews_sync() { var ctx = new CIAPI.Rpc.Client(RPC_URI); ctx.LogIn(USERNAME, PASSWORD); ListNewsHeadlinesResponseDTO news = ctx.ListNewsHeadlines("UK", 10); //do something with the news ctx.LogOut(); }
/// <summary> /// While the code is drastically simplified in comparison to the async pattern, you will typically /// want to do this on another thread and use BeingInvoke on the UI to marshal UI updates to the UI thread. /// This is probably the simplest pattern. /// </summary> private static void GetNewsSynchronously() { try { var ctx = new CIAPI.Rpc.Client(new Uri(TestConfig.RpcUrl)); ctx.LogIn(TestConfig.ApiUsername, TestConfig.ApiPassword); var headlinesResponse = ctx.ListNewsHeadlines("UK", 10); foreach (var item in headlinesResponse.Headlines) { // item contains id, date and headline. Console.WriteLine("{0} {1} {2}\r\n", item.StoryId, item.Headline, item.PublishDate); // fetch details to get all of the above and the body of the story var detailResponse = ctx.GetNewsDetail(item.StoryId.ToString()); Console.WriteLine("{0}", detailResponse.NewsDetail.Story.Substring(0, 35) + "..."); Console.WriteLine("\r\n-----------------------------------------------------------------------------\r\n"); } ctx.LogOut(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("\r\nPress enter to continue\r\n"); Console.ReadLine(); } #endregion }