public static void GetAndPrintAllData() { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(String.Format(SERVICE_URL, SERVICE_PORT)); HttpResponseMessage response = client.GetAsync(GET_ACTION).Result; OperationsOnDatabase odb = new OperationsOnDatabase(); if (response.IsSuccessStatusCode) { IEnumerable <ErrorClass> result = response.Content.ReadAsAsync <IEnumerable <ErrorClass> >().Result; List <ErrorClass> templist = new List <ErrorClass>(); Console.WriteLine(" Data:"); foreach (ErrorClass value in result) { // Console.WriteLine(" " + value); templist.Add(value); } foreach (var temp in templist) { //Console.WriteLine("templist " + temp); odb.AddErrorLogsFromRest(temp.Loglevel, temp.ApplicationId, temp.ErrorText); } Console.WriteLine(); } else { Console.WriteLine("ERROR: {0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } }
private static void GetAndPrintAllData() { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(String.Format(SERVICE_URL, SERVICE_PORT)); HttpResponseMessage response = client.GetAsync(GENERAL_ACTION).Result; OperationsOnDatabase odb = new OperationsOnDatabase(); List <MyData> list2 = new List <MyData>(); if (response.IsSuccessStatusCode) { // in order to make this work, this project needs a reference to System.Net.Http.Formatting IEnumerable <MyData> result = response.Content.ReadAsAsync <IEnumerable <MyData> >().Result; Console.WriteLine(" Data:"); foreach (MyData aRecord in result) { //odb.AddErrorLogsFromRest(aRecord.Id, aRecord.AppId,aRecord.Text ); list2.Add(aRecord); Console.WriteLine(" " + aRecord); } foreach (MyData aRecord in list2) { odb.AddErrorLogsFromRest(aRecord.Id, aRecord.AppId, aRecord.Text); Console.WriteLine(" " + aRecord); } Console.WriteLine(); } else { Console.WriteLine("ERROR: {0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } }
public static void CreateItem(ErrorClass newItem) { OperationsOnDatabase odb = new OperationsOnDatabase(); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(String.Format(SERVICE_URL, SERVICE_PORT)); odb.AddErrorLogsFromRest(newItem.Loglevel, newItem.ApplicationId, newItem.ErrorText); client.PostAsJsonAsync(GET_ACTION, newItem).Wait(); }