예제 #1
0
        static async Task Main(string[] args)
        {
            var server = new G.Server
            {
                Services = { Generated.SampleService.BindService(new SampleServiceImplementation()) },
                Ports    = { new G.ServerPort("127.0.0.1", 5000, G.ServerCredentials.Insecure) }
            };

            server.Start();

            var t = Task.Run(async() =>
            {
                try
                {
                    await Task.Delay(1000);
                    var client = GrpcClientFactory.Create <Service.ISampleService>(new GrpcClientOptions {
                        Url = "127.0.0.1", Port = 5000
                    }, new ProtoBufSerializer());
                    var request = new Service.SampleRequest {
                        Value = 1
                    };
                    var response = await client.SendAsync(request, CancellationToken.None);
                    Console.WriteLine("{0} -> {1}", request.Value, response.Value);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            });

            await t;
            await server.ShutdownAsync();
        }
예제 #2
0
        public void Create_WithBaseAddress_ReturnInstance()
        {
            // Arrange & Act
            var client = GrpcClientFactory.Create <GreeterClient>("http://localhost");

            // Assert
            Assert.IsNotNull(client);
        }
예제 #3
0
        public TResponse When <TResponse>(Func <TGrpcClient, TResponse> grpcCall)
        {
            PreApiCall?.Invoke();

            WriteHeader();

            var gRpcClient = _grpcClientFactory.Create <TGrpcClient>();

            var response = grpcCall(gRpcClient);

            _eventAggregator.PublishGrpcResponse(new GrpcResponse(response));

            return(response);
        }
예제 #4
0
 private TClient CreateClient <TClient>(IChannel channel) where TClient : ClientBase <TClient>
 {
     if (channel is CoreChannel coreChannel)
     {
         return((TClient)Activator.CreateInstance(typeof(TClient), coreChannel.Channel));
     }
     else if (channel is HttpClientChannel httpClientChannel)
     {
         return(GrpcClientFactory.Create <TClient>(httpClientChannel.BaseAddress, httpClientChannel.HttpClientHandler, loggerFactory));
     }
     else
     {
         throw new Exception("Unexpected channel type.");
     }
 }
예제 #5
0
 private TClient CreateClient <TClient>(IChannel channel) where TClient : ClientBase <TClient>
 {
     if (channel is CoreChannel coreChannel)
     {
         return((TClient)Activator.CreateInstance(typeof(TClient), coreChannel.Channel));
     }
     else if (channel is HttpClientChannel httpClientChannel)
     {
         return(GrpcClientFactory.Create <TClient>($"http://{options.ServerHost}:{options.ServerPort}", certificate: null));
     }
     else
     {
         throw new Exception("Unexpected channel type.");
     }
 }
 public Task ConnectAsync()
 {
     _client = GrpcClientFactory.Create <Greeter.GreeterClient>(BaseUri);
     return(Task.CompletedTask);
 }
 public Task ConnectAsync()
 {
     _client = GrpcClientFactory.Create <Greeter.GreeterClient>("https://" + Target);
     return(Task.CompletedTask);
 }