public async Task Invoke(DownstreamContext context) { var httpStatusCode = HttpStatusCode.OK; var buildRequest = await _dotNettyRequestBuilder.BuildRequest(context); string resultMessage; if (buildRequest.IsError) { resultMessage = "bad request"; httpStatusCode = HttpStatusCode.BadRequest; Logger.LogDebug(resultMessage); } else { try { var endpoint = new IPEndPoint(IPAddress.Parse(context.DownstreamRequest.Host), context.DownstreamRequest.Port); var serviceId = context.DownstreamRequest.AbsolutePath.TrimStart('/'); var result = await _serviceProxyProvider.InvokeAsync <object>(buildRequest.Data, serviceId, endpoint); resultMessage = JsonConvert.SerializeObject(result); } catch (RpcException ex) { httpStatusCode = HttpStatusCode.InternalServerError; resultMessage = $"rpc exception."; Logger.LogError("apigateway dotnetty client error", ex); } catch (Exception ex) { httpStatusCode = HttpStatusCode.ServiceUnavailable; resultMessage = $"error in request netty service."; Logger.LogError($"{resultMessage}--{context.DownstreamRequest.ToUri()}", ex); } } OkResponse <DotNettyHttpContent> httpResponse = new OkResponse <DotNettyHttpContent>(new DotNettyHttpContent(resultMessage)); //context.HttpContext.Response.ContentType = "application/json"; context.DownstreamResponse = new DownstreamResponse(httpResponse.Data, httpStatusCode, httpResponse.Data.Headers, string.Empty); }