diff --git a/samples/OcelotGateway/OcelotGateway.csproj b/samples/OcelotGateway/OcelotGateway.csproj index e121e47..3d2c8aa 100644 --- a/samples/OcelotGateway/OcelotGateway.csproj +++ b/samples/OcelotGateway/OcelotGateway.csproj @@ -1,14 +1,13 @@  - netcoreapp3.1 + net5.0 InProcess - - + diff --git a/src/GrpcJsonTranscoder/DownStreamContextExtensions.cs b/src/GrpcJsonTranscoder/DownStreamContextExtensions.cs index 6a01ef2..c452f25 100644 --- a/src/GrpcJsonTranscoder/DownStreamContextExtensions.cs +++ b/src/GrpcJsonTranscoder/DownStreamContextExtensions.cs @@ -32,7 +32,7 @@ public static async Task HandleGrpcRequestAsync(this DownstreamContext context, { var methodPath = context.DownstreamReRoute.DownstreamPathTemplate.Value; var grpcAssemblyResolver = context.HttpContext.RequestServices.GetService(); - var methodDescriptor = grpcAssemblyResolver.FindMethodDescriptor(methodPath.Split('/').Last().ToUpperInvariant()); + var methodDescriptor = grpcAssemblyResolver.FindMethodDescriptor(methodPath.TrimStart('/').Replace("/", ".").Last().ToUpperInvariant()); if (methodDescriptor == null) { @@ -55,7 +55,7 @@ public static async Task HandleGrpcRequestAsync(this DownstreamContext context, logger.LogInformation($"Request object data is {requestJsonData}"); var loadBalancerFactory = context.HttpContext.RequestServices.GetService(); - var loadBalancerResponse = await loadBalancerFactory.Get(context.DownstreamReRoute, context.Configuration.ServiceProviderConfiguration); + var loadBalancerResponse = loadBalancerFactory.Get(context.DownstreamReRoute, context.Configuration.ServiceProviderConfiguration); var serviceHostPort = await loadBalancerResponse.Data.Lease(context); var downstreamHost = $"{serviceHostPort.Data.DownstreamHost}:{serviceHostPort.Data.DownstreamPort}"; @@ -77,14 +77,13 @@ public static async Task HandleGrpcRequestAsync(this DownstreamContext context, { client = new MethodDescriptorCaller(channel); } - - var concreteObject = JsonConvert.DeserializeObject(requestJsonData, methodDescriptor.InputType.ClrType); + var concreteObject = Google.Protobuf.JsonParser.Default.Parse(upstreamHeaders["x-grpc-body-data"], methodDescriptor.InputType); var result = await client.InvokeAsync(methodDescriptor, context.HttpContext.GetRequestHeaders(), concreteObject); logger.LogDebug($"gRPC response called with {JsonConvert.SerializeObject(result)}"); var jsonSerializer = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; var response = new OkResponse(new GrpcHttpContent(JsonConvert.SerializeObject(result, jsonSerializer))); - + context.HttpContext.Response.ContentLength = response.Data.ReadAsByteArrayAsync().Result.Length; var httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK) { Content = response.Data diff --git a/src/GrpcJsonTranscoder/Grpc/GrpcAssemblyResolver.cs b/src/GrpcJsonTranscoder/Grpc/GrpcAssemblyResolver.cs index 2c310e1..5782c05 100644 --- a/src/GrpcJsonTranscoder/Grpc/GrpcAssemblyResolver.cs +++ b/src/GrpcJsonTranscoder/Grpc/GrpcAssemblyResolver.cs @@ -66,7 +66,7 @@ private ConcurrentDictionary GetMethodDescriptors(para foreach (var method in svr.Methods) { _logger.LogInformation($"Add method name #{method.Name.ToUpper()} into the assembly resolver."); - methodDescriptorDic.TryAdd(method.Name.ToUpper(), method); + methodDescriptorDic.TryAdd(method.FullName.ToUpper(), method); } } } diff --git a/src/GrpcJsonTranscoder/GrpcJsonTranscoder.csproj b/src/GrpcJsonTranscoder/GrpcJsonTranscoder.csproj index f647836..cc86e40 100644 --- a/src/GrpcJsonTranscoder/GrpcJsonTranscoder.csproj +++ b/src/GrpcJsonTranscoder/GrpcJsonTranscoder.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1 + net5.0 true @@ -17,16 +17,16 @@ - - - - - - - - - - + + + + + + + + + +