public virtual CallServiceResponseObj CallService(CallServiceRequestObj data) { var result = new CallServiceResponseObj(); var url = data.EndpointMethod; log.Info(string.Format("Sending REST request to service: {0} {1}", data.RequestType, url)); string headers = string.Empty; var headerCollection = new WebHeaderCollection(); if (data.Headers != null) { foreach (var h in data.Headers) { headers += h + " "; headerCollection.Add(h.Key, h.Value); } } log.Info(string.Format("- using headers: {0}", headers)); WebRequestHelper.WebResponse response = null; if (data.RequestType == "GET") { response = WebRequestHelper.Get(url, headerCollection, true); } else if (data.RequestType == "POST") { response = WebRequestHelper.Post(url, data.Body, headerCollection, true); } else if (data.RequestType == "DELETE") { response = WebRequestHelper.Delete(url, data.Body, headerCollection, true); } else if (data.RequestType == "PUT") { response = WebRequestHelper.Put(url, data.Body, headerCollection, true); } else { throw new Exception(string.Format("The request type {0} is not supported.", data.RequestType)); } result.Body = response.Body; result.StatusCode = (int)response.HttpStatusCode; return(result); }
public WebRequestHelper.WebResponse MakeGenericCall(string url, string method, string body = null, WebHeaderCollection headers = null) { log.Info("Make generic call to ServiceRegistry"); WebRequestHelper.WebResponse response = null; url = serviceRegistryBasePath + url; if (method == "GET") { response = WebRequestHelper.Get(url, headers, false); } else if (method == "POST") { response = WebRequestHelper.Post(url, body, headers: headers, UseCertificate: false); } return(response); }
public WebRequestHelper.WebResponse MakeGenericCall(string url, string method, string body = null, WebHeaderCollection headers = null) { log.Info("Make generic call to IdentityRegistry"); WebRequestHelper.WebResponse response = null; url = idRegistryBaseUrl + url; if (method == "GET") { response = WebRequestHelper.Get(url, headers, true); } else if (method == "POST") { response = WebRequestHelper.Post(url, body, headers: headers, UseCertificate: true); } if (response.HttpStatusCode != HttpStatusCode.OK) { throw new WebException(response.ErrorMessage); } return(response); }