예제 #1
0
        public TestSetMessage SendREFI(TestSetMessage postMessage)
        {
            postMessage.Header.Command1 = "RE";
            postMessage.Header.Command2 = "FI";

            return(PostToPTS(postMessage));
        }
예제 #2
0
        public TestSetMessage PostToPTS(TestSetMessage json)
        {
            using (var client = new HttpClient())
            {
                TestSetMessage      responseMessage = new TestSetMessage();
                HttpResponseMessage httpResponse;
                client.BaseAddress = new Uri(ServerUri);

                OnPTSMessageSending();
                try
                {
                    httpResponse = client.PostAsJsonAsync(ServiceUrl, json).Result;
                    OnPTSMessageReceived();
                }
                catch (Exception ex)
                {
                    responseMessage.Success          = false;
                    responseMessage.Response.Message = (string.Format("Could not contact the PTS service. ServiceUrl: {0} , ServerUri: {1}, Error: {2}", ServiceUrl, ServerUri, ex));
                    return(responseMessage);
                }


                if (httpResponse.IsSuccessStatusCode)
                {
                    try
                    {
                        responseMessage         = httpResponse.Content.ReadAsAsync <TestSetMessage>().Result;
                        responseMessage.Success = true;
                    }
                    catch (Exception ex)
                    {
                        responseMessage                  = new TestSetMessage();
                        responseMessage.Success          = false;
                        responseMessage.Response.Message = string.Format("PTS service error ServiceUrl: { 0} , ServerUri: { 1}, Error: { 2}", ServiceUrl, ServerUri, ex);
                    }
                }
                else
                {
                    responseMessage.Response.Message = string.Format("Something went wrong communicating with PTS. Response: {0}", httpResponse);
                }
                return(responseMessage);
            }
        }