예제 #1
0
        internal Task <ResponseDoc> SendRequestAsync(InvoicesDoc invoicesDoc)
        {
            var requestContent = XmlManipulator.Serialize(invoicesDoc).DocumentElement.OuterXml;

            Logger?.Debug("Created XML document from DTOs.", new { XmlString = requestContent });

            var requestMessage = BuildHttpPostMessage(requestContent);

            return(SendAsync(
                       sendFunc:
                       () => HttpClient.SendAsync(requestMessage),
                       buildErrorResponseFunc:
                       (errorCode, errorMessage) => BuildResponseDocWithErrors(errorCode, errorMessage, invoicesDoc.Invoices),
                       buildResponseFunc:
                       async httpResponseMessage =>
            {
                if (httpResponseMessage.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                {
                    return BuildResponseDocWithErrors(SendInvoiceErrorCodes.UnauthorizedErrorCode, "Authorization error", invoicesDoc.Invoices);
                }

                var responseContent = await httpResponseMessage.Content.ReadAsStringAsync().ConfigureAwait(continueOnCapturedContext: false);

                var responseDoc = XmlManipulator.Deserialize <ResponseDoc>(responseContent);
                Logger?.Debug("Result received and successfully deserialized.", responseDoc);

                return responseDoc;
            }
                       ));
        }
예제 #2
0
        internal async Task <ResponseDoc> SendRequestAsync(InvoicesDoc invoicesDoc)
        {
            var requestContent = XmlManipulator.Serialize(invoicesDoc).DocumentElement.OuterXml;
            var requestMessage = BuildHttpPostMessage(requestContent);

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var response = await HttpClient.SendAsync(requestMessage).ConfigureAwait(continueOnCapturedContext: false);

            stopwatch.Stop();
            Logger?.Info($"HTTP request finished in {stopwatch.ElapsedMilliseconds}ms.", new { HttpRequestDuration = stopwatch.ElapsedMilliseconds });

            var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(continueOnCapturedContext: false);

            return(XmlManipulator.Deserialize <ResponseDoc>(responseContent));
        }