private string RestServiceCall(string url) { try { string responseText = string.Empty; ExtendedWebClient client = new ExtendedWebClient(new Uri(url)); client.Headers[ECoupounConstants.ContentTypeText] = ECoupounConstants.ContentTypeValue; MemoryStream stream = new MemoryStream(); byte[] data = client.UploadData(string.Format("{0}", url), "POST", stream.ToArray()); stream = new MemoryStream(data); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(string)); serializer = new DataContractJsonSerializer(typeof(string)); responseText = (string)serializer.ReadObject(stream); return responseText; } catch (Exception ex) { return ex.Message; } }
/// <summary> /// Called when time elapsed /// </summary> /// <param name="obj"></param> private void GetProducts(object obj) { try { LogHelper.WriteTraceLog("GetProducts Called"); var url = ECoupounConstants.BestBuyRESTServiceURL + ECoupounConstants.InsertData; string responseText = string.Empty; ExtendedWebClient client = new ExtendedWebClient(new Uri(url)); client.Headers[ECoupounConstants.ContentTypeText] = ECoupounConstants.ContentTypeValue; MemoryStream stream = new MemoryStream(); byte[] data = client.UploadData(string.Format("{0}", url), "POST", stream.ToArray()); stream = new MemoryStream(data); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(string)); serializer = new DataContractJsonSerializer(typeof(string)); responseText = (string)serializer.ReadObject(stream); LogHelper.WriteTraceLog(responseText); _reconnectionTimer.Change(Convert.ToInt32(GetNextInterval()), 0); } catch (Exception ex) { LogHelper.WriteTraceLog(ex.Message); _reconnectionTimer.Change(Convert.ToInt32(GetNextInterval()), 0); } }