public CallServiceResponseObj CallService([FromBody] CallServiceRequestObj callServiceObj) { log.Info("Incoming request to " + GetCurrentMethod()); var requestString = JsonConvert.SerializeObject(callServiceObj, Formatting.Indented); //_logEventService.Init(EventDataType.PCM); _logEventService.LogInfo(EventNumber.SPIS_consumeService, EventDataType.Unknown, null, requestString); try { var result = _sscService.CallService(callServiceObj); return(result); } catch (HttpResponseException ex) { _logEventService.LogError(EventNumber.SPIS_consumeService, EventType.Error_internal, null, requestString + " " + ex.Response.ToString()); throw; } catch (Exception ex) { string msg = "SPIS internal server error. " + ex.Message; _logEventService.LogError(EventNumber.SPIS_consumeService, EventType.Error_internal, null, requestString + " " + ex.Message); throw CreateHttpResponseException(HttpStatusCode.InternalServerError, msg); } }
public string CallService(string body, string url, string requestType, string contentType) { var visurl = _visUrl + string.Format("/callService"); var result = new CallServiceResponseObj(); var request = new CallServiceRequestObj { Body = body, EndpointMethod = url, Headers = new List <Header> { new Header("content-type", contentType) }, RequestType = requestType }; WebHeaderCollection headers = new WebHeaderCollection(); headers.Add(HttpRequestHeader.ContentType, "application/json; charset=utf-8"); var json = request.ToJson(); var response = WebRequestHelper.Post(visurl, request.ToJson(), headers); return(response.Body); }
private void SendToAmssService(string message, string dataId, string amssEndpoint, Identity identity) { var paramList = new List <KeyValuePair <string, string> >(); var p1 = new KeyValuePair <string, string>("dataId", dataId); paramList.Add(p1); p1 = new KeyValuePair <string, string>("amssEndpoint", amssEndpoint); paramList.Add(p1); var requestObj = new CallServiceRequestObj { Body = message, EndpointMethod = WebRequestHelper.CombineUrl(amssEndpoint, "/amss/state_update"), Headers = null, RequestType = "POST", }; try { var headers = new List <Header> { new Header("content-type", "application/xml") }; requestObj.Headers = headers; _logEventService.LogInfo(EventNumber.SPIS_amss_request, EventDataType.PCM, paramList, JsonConvert.SerializeObject(requestObj, Newtonsoft.Json.Formatting.Indented)); var client = new SSC.Internal.SccPrivateService(); var queueResult = client.CallService(requestObj); if (queueResult.StatusCode < 200 || queueResult.StatusCode >= 300) { throw new Exception("Unable to send state update. " + queueResult.StatusCode + " " + queueResult.Body); } _logEventService.LogSuccess(EventNumber.SPIS_amss_response, EventDataType.Other, paramList, JsonConvert.SerializeObject(queueResult, Newtonsoft.Json.Formatting.Indented)); } catch (Exception ex) { log.Error(ex.Message, ex); _logEventService.LogError(EventNumber.SPIS_amss_request, EventType.Error_internal, paramList, JsonConvert.SerializeObject(requestObj, Newtonsoft.Json.Formatting.Indented)); // Send notification var notification = new Interfaces.Notification(); notification.FromOrgName = identity.Name; notification.FromOrgId = identity.UID; notification.FromServiceId = InstanceContext.CallerServiceId; notification.NotificationType = EnumNotificationType.ERROR_MESSAGE; notification.Subject = "Unable to send message"; notification.Body = string.Format("Unable to send message with id {0} to identity {1}, {2}. {3}", dataId, identity.Name, identity.UID, ex.Message); notification.NotificationSource = EnumNotificationSource.SPIS; _notificationService.Notify(notification); } }
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 CallServiceResponseObj CallService([FromBody] CallServiceRequestObj callServiceObj) { log.Info("Incoming request to " + GetCurrentMethod()); var requestString = JsonConvert.SerializeObject(callServiceObj, Formatting.Indented); _logEventService.LogInfo(EventNumber.VIS_consumeService, EventDataType.Unknown, null, requestString); try { var result = _sscService.CallService(callServiceObj); var responseString = JsonConvert.SerializeObject(result, Formatting.Indented); _logEventService.LogSuccess(EventNumber.VIS_consumeService, EventDataType.Unknown, null, responseString); //Set last interaction time var conInfo = _connectionInformationService.Get().FirstOrDefault(); if (conInfo == null) { _connectionInformationService.Insert(new ConnectionInformation { LastInteraction = DateTime.UtcNow }); } else { conInfo.LastInteraction = DateTime.UtcNow; _connectionInformationService.Update(conInfo); } _context.SaveChanges(); return(result); } catch (HttpResponseException ex) { var errorString = JsonConvert.SerializeObject(ex.Response, Formatting.Indented); _logEventService.LogError(EventNumber.VIS_consumeService, EventType.Error_internal, null, errorString); throw; } catch (Exception ex) { string msg = "VIS internal server error. " + ex.Message; _logEventService.LogError(EventNumber.VIS_consumeService, EventType.Error_internal, null, ex.Message); throw CreateHttpResponseException(HttpStatusCode.InternalServerError, msg); } }