Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static T SendRequest<T>(string methodName, string requestData)
- {
- WebClient client = new WebClient();
- try
- {
- string serviceUrl = System.Configuration.ConfigurationManager.AppSettings["WS.URL"];
- dynamic logRequest = JObject.Parse(requestData);
- logRequest.passwd = "NO VIEW in logs";
- log.Trace(string.Format("{0}{1}\n{2}", serviceUrl, methodName, logRequest.ToString()));
- client.Headers["Content-type"] = "application/json";
- MemoryStream stream = new MemoryStream();
- byte[] data;// = client.UploadData(string.Format("{0}{1}", serviceUrl, methodName), "POST", Encoding.Default.GetBytes(requestData));
- var task = Task.Run(() => client.UploadData(string.Format("{0}{1}", serviceUrl, methodName), "POST", Encoding.UTF8.GetBytes(requestData)));
- if ((task.Wait(TimeSpan.FromSeconds(15)) && (methodName == "GetTenantsToPrint" || methodName == "RegisterVips")) || methodName != "GetTenantsToPrint")
- {
- data = task.Result;
- }
- else
- throw new Exception("Timed out");
- stream = new MemoryStream(data);
- DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
- T response = (T)serializer.ReadObject(stream);
- //(T)serializer.ReadObject()
- log.Trace(JsonConvert.SerializeObject(response));
- return response;
- }
- catch (Exception ex)
- {
- string method = string.Format("{0}.{1}", System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, System.Reflection.MethodBase.GetCurrentMethod().Name);
- log.Error(ex, method);
- return default(T);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement