Exemplo n.º 1
0
        private Task <HttpResponseMessage> SendRequestAsync <TRequest>(string endpoint, TRequest request)
            where TRequest : class
        {
            var content = new StringContent(XmlManipulator.Serialize(request), Encoding.UTF8, "application/xml");
            var uri     = new Uri(ServiceInfo.BaseUrls[Environment], $"{ServiceInfo.RelativeServiceUrl}{endpoint}");

            return(HttpClient.PostAsync(uri, content));
        }
Exemplo n.º 2
0
        private async Task <ResponseResult <TResult, TCode> > DeserializeAsync <TDto, TResult, TCode>(HttpResponseMessage response, Func <TDto, ResponseResult <TResult, TCode> > successFunc)
            where TDto : class
            where TResult : class
            where TCode : struct
        {
            var content = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                return(successFunc(XmlManipulator.Deserialize <TDto>(content)));
            }
            else
            {
                var errorResult = XmlManipulator.Deserialize <Dto.GeneralErrorResponse>(content);
                return(new ResponseResult <TResult, TCode>(generalErrorMessage: ErrorResult <TCode> .Map(errorResult)));
            }
        }