Пример #1
0
        //[Authorize]
        public async Task <object> ExecuteService(string server, string service, string method, [FromBody] Dictionary <string, object> inputBody)
        {
            method = method.Substring(0, 1).ToUpper() + method.Substring(1);
            var clientType = await GetClientType($"{service}.{method}");

            var client = await _clientProvider.GetClientAsync(server, clientType);

            var descriptor =
                _gatewayProvider.MethodDescriptors.FirstOrDefault(item => item.Name == method);

            var methodModel = new GrpcGatewayMethod()
            {
                Type    = descriptor?.InputType.ClrType,
                Request = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(inputBody), descriptor?.InputType.ClrType)
            };

            var methodInvoke = clientType.GetMethod(method,
                                                    new Type[] { methodModel.Type,
                                                                 typeof(Metadata),
                                                                 typeof(global::System.DateTime),
                                                                 typeof(global::System.Threading.CancellationToken) });


            var result = methodInvoke?.Invoke(client,
                                              new object[] { methodModel.Request, null, null, default(global::System.Threading.CancellationToken) });

            return(new KetchupResponse(result));
        }
Пример #2
0
        public async Task <object> ExecuteService(string server, string service, [FromBody] Dictionary <string, object> inputBody)
        {
            _gatewayProvider.MapClients.TryGetValue(service, out var value);

            var client = await _clientProvider.GetClientAsync(server, value);

            var descriptor =
                _gatewayProvider.MethodDescriptors.FirstOrDefault(item => item.Name == service);

            var methodModel = new GrpcGatewayMethod()
            {
                Type    = descriptor?.InputType.ClrType,
                Request = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(inputBody), descriptor?.InputType.ClrType)
            };

            var method = _gatewayProvider.MapClients[service].GetMethod(service,
                                                                        new Type[] { methodModel.Type,
                                                                                     typeof(Metadata),
                                                                                     typeof(global::System.DateTime),
                                                                                     typeof(global::System.Threading.CancellationToken) });

            var result = method?.Invoke(client,
                                        new object[] { methodModel.Request, null, null, default(global::System.Threading.CancellationToken) });

            return(result);
        }