Exemplo n.º 1
0
        private async Task <ResponseContext> InternalInvokeAsync(MethodInfo targetMethod, object[] args, Type genericReturnType = null)
        {
            var requestContext = new RequestContext(targetMethod,
                                                    _proxyContext.ProxyType,
                                                    _proxyContext.ClientIp,
                                                    _proxyContext.UserAgent,
                                                    _proxyContext.TokenCookie,
                                                    _proxyContext.QueryString,
                                                    args);

            RequestDescriptor descriptor = await _proxyManager.CreateDescriptorAsync(requestContext);

            ResponseContext responseContext = null;

            try
            {
                HttpResponseMessage response = null;
                var    httpClient            = _proxyManager.HttpClient;
                string metadata = string.Empty;
                response = await httpClient.SendAsync(descriptor.Request);

                responseContext = await ProxyResultExecutor.ExecuteAsync(response,
                                                                         descriptor,
                                                                         genericReturnType);
            }
            catch (Exception ex)
            {
                var properties = CreateContextProperties(descriptor, targetMethod);
                var result     = properties.GetConfigurationContextDetail(properties);
                throw new ProxyException(result, ex);
            }

            if ((int)responseContext.Response.StatusCode == StatusCodes.Status404NotFound)
            {
                var properties = CreateContextProperties(descriptor, targetMethod);
                var result     = properties.GetConfigurationContextDetail(properties);
                throw new ProxyException(result, new HttpRequestException());
            }

            return(responseContext);
        }