static async Task Main(string[] args) { using var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new Greeter.GreeterClient(channel); await UnaryCallExample(client); Console.WriteLine("Shutting down"); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
protected async Task SayHello() { var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new Greeter.GreeterClient(channel); var reply = await client.SayHelloAsync(new HelloRequest { Name = "Blazor gRPC Client" }); Greeting = reply.Message; await channel.ShutdownAsync(); }
static async Task Main(string[] args) { using var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new Greeter.GreeterClient(channel); var reply = await client.SayHelloAsync( new HelloRequest { Name = "GreeterClient" }); Console.WriteLine("Greeting: " + reply.Message); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
static async Task Main(string[] args) { // The port number(5001) must match the port of the gRPC server. var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new Greeter.GreeterClient(channel); var reply = await client.SayHelloAsync( new HelloRequest { Name = "GreeterClient" }); Console.WriteLine("Greeting: " + reply.Message); Console.WriteLine("Press any key to exit..."); }
public async Task GreeterService_SayHelloUnary_ReturnsCorrectResponse() { // Arrange var client = new Greeter.GreeterClient(Channel); // Act var response = await client.SayHelloUnaryAsync(new HelloRequest { Name = "Joe" }); // Assert Assert.AreEqual("Hello Joe", response.Message); }
private void OnLoaded(object sender, RoutedEventArgs e) { channel = new Channel("localhost", 8099, ChannelCredentials.Insecure); client = new Greeter.GreeterClient(channel); var response = client.SayHello(new HelloRequest() { Name = "Link Sun" }); lvResponse.Items.Add(response); }
private static async Task HttpsTest() { var httpsChannel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new Greeter.GreeterClient(httpsChannel); var reply = await client.SayHelloAsync(new HelloRequest() { Name = "Https test" }); Console.WriteLine(reply.Message); }
public async Task <IActionResult> GetFromgRPCWithToken() { using GrpcChannel channelCommunication = GrpcChannel.ForAddress("https://localhost:5001"); var client = new Greeter.GreeterClient(channelCommunication); var headers = new Metadata(); headers.Add("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9lbWFpbGFkZHJlc3MiOiJpaGFiQHV0b3Bpb3MubmV0IiwiaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS93cy8yMDA4LzA2L2lkZW50aXR5L2NsYWltcy9yb2xlIjoiY3VzdG9tZXIiLCJleHAiOjE2MjA2NTA2ODUsImlzcyI6InV0b3Bpb3MiLCJhdWQiOiJ1dG9waW9zIn0.55JBPBMjSN7nnzfgRgpWMvPiBgXzPVKYQrOnmbZfG_8"); HelloReply response = await client.SayHelloAsync(new HelloRequest { Name = "ihab" }, headers); return(Ok(new { message = "test" })); }
public async Task RunAsync() { var serverUrl = _configuration["RemoteServices:Default:BaseUrl"]; using var channel = GrpcChannel.ForAddress(serverUrl); var client = new Greeter.GreeterClient(channel); var reply = await client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" }); Console.WriteLine("Greeting: " + reply.Message); }
public GrpcClient() { // // https://docs.microsoft.com/pt-br/aspnet/core/grpc/troubleshoot?view=aspnetcore-3.1#call-insecure-grpc-services-with-net-core-client // // macOS: This switch must be set before creating the GrpcChannel/HttpClient. // AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); // channel = GrpcChannel.ForAddress("http://localhost:5000"); // The port number(5001) must match the port of the gRPC server. channel = GrpcChannel.ForAddress("https://localhost:5001"); client = new Greeter.GreeterClient(channel); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); GrpcChannel channel = GrpcChannel.ForAddress("https://127.0.0.1:9999"); Greeter.GreeterClient client = new Greeter.GreeterClient(channel); HelloRequest request = new HelloRequest(); request.Names.Add("1"); request.Names.Add("2"); request.Names.Add("3"); }
private static async Task SingleGrpcMessageResponse() { GrpcChannel grpcChannel = GrpcChannel.ForAddress("https://localhost:5001"); Greeter.GreeterClient greeterClient = new Greeter.GreeterClient(grpcChannel); HelloReply helloReply = await greeterClient.SayHelloAsync(new HelloRequest { Name = "gRPC Demonstration!" }); Console.WriteLine($"Message From gRPC Server: {helloReply.Message}"); }
static async Task Main(string[] args) { var channel = GrpcChannel.ForAddress("http://127.0.0.1:5000"); var client = new Greeter.GreeterClient(channel); var reply = await client.SayHelloAsync(new HelloRequest { Name = "gRPC!" }); Console.WriteLine(reply.Message); }
static void Main(string[] args) { using (var channel = GrpcChannel.ForAddress("https://localhost:5001")) { var client = new Greeter.GreeterClient(channel); var reply = client.SayHello(new HelloRequest { Name = "Georgi" }); Console.WriteLine(reply.Message); } }
static async Task Main(string[] args) { // The port number(5001) must match the port of the gRPC server. using var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new Greeter.GreeterClient(channel); var reply = await client.HelloWorldAsync(new EmptyRequest()); Console.WriteLine("Greeting: " + reply.Message); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
public async Task <ActionResult <string> > Get(string name) { var channel = GrpcChannel.ForAddress("https://localhost:5001", new GrpcChannelOptions { LoggerFactory = _loggerFactory }); var client = new Greeter.GreeterClient(channel); var reply = await client.SayHelloAsync(new HelloRequest { Name = name }); return(Ok(reply.Message)); }
private static async Task UnaryCallExample(Greeter.GreeterClient client) { // 'grpc-internal-encoding-request' is a special metadata value that tells // the client to compress the request. This metadata is not sent as a header. var metadata = new Metadata(); metadata.Add("grpc-internal-encoding-request", "gzip"); var reply = await client.SayHelloAsync(new HelloRequest { Name = "GreeterClient" }, headers : metadata); Console.WriteLine("Greeting: " + reply.Message); }
private static async Task CallOneTime() { Write("Tell me your name:"); var name = ReadLine(); var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new Greeter.GreeterClient(channel); var response = await client.SayHelloAsync(new HelloRequest { Name = name }); WriteLine(response.Message); ReadLine(); }
static async Task Main(string[] args) { var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new Greeter.GreeterClient(channel); Console.WriteLine("Please insert your name: "); string name = Console.ReadLine(); await client.SayHelloAsync(new HelloRequest { Message = name }); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
public async void JustSayHello() { var url = Variables.GetEnvironmentVariable(VariablesType.URL); using var channel = GrpcChannel.ForAddress(url); string request = "Test"; var client = new Greeter.GreeterClient(channel); var reply = await client.SayHelloAsync( new HelloRequest { Name = request }); Assert.Contains(request, reply.Message); }
private static async Task TestHello() { using (var channel = GrpcChannel.ForAddress("https://localhost:5001")) { var client = new Greeter.GreeterClient(channel); var reply = await client.SayHelloAsync(new HelloRequest { Name = "Eleven" }); Console.WriteLine("Greeter 服务返回数据: " + reply.Message); //client.SayHello(new HelloRequest { Name = "Eleven" }); } }
static async Task Main(string[] args) { var channel = new Channel("127.0.0.1:5000", ChannelCredentials.Insecure); var client = new Greeter.GreeterClient(channel); var reply = await client.SayHelloAsync( new HelloRequest { Name = "GreeterClient" }); Console.WriteLine("Greeting: " + reply.Message); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
static async Task Main(string[] args) { var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new Greeter.GreeterClient(channel); var request = new HelloRequest { Name = "Benjamin Franklin" }; var response = await client.SayHelloAsync(request); Console.WriteLine(response.Message); }
static string Greet() { Console.WriteLine($" Using gRPC to access {Hostname}:{Port}"); var channel = Grpc.Net.Client.GrpcChannel.ForAddress($"https://{Hostname}:{Port}"); var client = new Greeter.GreeterClient(channel); var result = client.SayHello(new HelloRequest() { Name = "Mr. Cuddlesworth" }); return(result.Message); }
public async Task testing_Bidrectional() { var greaterClient = new Greeter.GreeterClient(channel); //using (var call = customerClient.) using (var call = greaterClient.StreamingBothWays()) { while (await call.ResponseStream.MoveNext()) { } } }
public async Task testing_UnaryCall() { greeterClient = new Greeter.GreeterClient(channel); // grpc-internal-encoidng-request is a special metadata value that tells the client to compress the request. //This metadata uis only used in the client is not sent as a header to the server var metadata = new Metadata(); metadata.Add("grpc-internal-encoding-request", "gzip"); var response = await greeterClient.SayHelloAsync(new HelloRequest { Name = "KevinCLient" }, headers : metadata); Console.WriteLine("From server : " + response.Message); }
static void Main(string[] args) { using var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new Greeter.GreeterClient(channel); var rsp = client.SayHello(new HelloRequest() { Name = "Abernathy" }); Console.WriteLine(rsp.Message); }
static async Task Main(string[] args) { Environment.SetEnvironmentVariable("GRPC_TRACE", "all,-timer,-timer_check"); Environment.SetEnvironmentVariable("GRPC_VERBOSITY", "INFO"); GrpcEnvironment.SetLogger(new ConsoleLogger()); var server = new Server(); server.Ports.Add("127.0.0.1", InsecurePort, ServerCredentials.Insecure); server.Ports.Add("127.0.0.1", SecurePort, MakeBadSslServerCredentials()); server.Services.Add(Greeter.BindService(new GreeterImpl())); try { Console.WriteLine("Starting...."); server.Start(); } catch (IOException ex) { Console.WriteLine($"Caught {ex}"); } foreach (var p in server.Ports) { Console.WriteLine($"{p.Host} @ {p.Port} bound to {p.BoundPort}"); } // Prior to 2.32.0, one needed to uncomment the following line // to clean up the one bound port & see the expected // RpcException. With 2.32.0, the behavior is what would be // expected. //await server.ShutdownAsync(); var channel = new Channel("127.0.0.1", InsecurePort, ChannelCredentials.Insecure); var client = new Greeter.GreeterClient(channel); try { Console.WriteLine("Making call. Ideally we'll get a RpcException with a connection failure."); var call = client.SayHelloAsync(new HelloRequest { Name = "This is the outgoing request name." }); HelloReply reply = await call; Console.WriteLine($"Got: {reply.Message}"); } catch (RpcException ex) { Console.WriteLine($"Client RPC exception: {ex}"); } }
public override Task <HelloReply> SayHello(HelloRequest request, ServerCallContext context) { var httpContext = context.GetHttpContext(); var c = httpContext.Request.Headers.Count; _logger.LogInformation($"HttpContext.Request.Headers.Count:{c}"); var msg = request.Name; try { //元のソース var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new Helloer.HelloerClient(channel); //元のソース var response = client.SayHello( new HelloService.HelloRequest { Name = msg }); msg = response.Hello.Message; } catch (Exception ex) { throw new SystemException("", ex); } try { //元のソース var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new Greeter.GreeterClient(channel); //元のソース var response = client.SayHello2( new HelloRequest { Name = msg }); msg = response.Hello.Message; } catch (Exception ex) { throw new SystemException("", ex); } return(Task.FromResult(new HelloReply { ResultStatus = ResultStatus.Ok, Hello = new Hello { Message = "Greeter.SayHello:" + msg } })); }
static async Task Main(string[] args) { using var loggerFactory = LoggerFactory.Create(builder => { builder .AddFilter("client.Program", LogLevel.Debug) .AddFilter("Grpc", LogLevel.Debug) .AddConsole(); }); var logger = loggerFactory.CreateLogger <Program>(); AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); // AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true); var options = new GrpcChannelOptions(); options.Credentials = ChannelCredentials.Insecure; options.LoggerFactory = loggerFactory; using var channel = GrpcChannel.ForAddress("http://localhost:5051", options); var client = new Greeter.GreeterClient(channel); var input = string.Empty; while (true) { Console.WriteLine("Press enter the message to send or type `quit` to exit"); input = Console.ReadLine(); if (input.Equals("quit")) { break; } try { var reply = await client.SayHelloAsync( new HelloRequest { Name = input }, deadline : DateTime.UtcNow.AddSeconds(30)); Console.WriteLine("Response received: " + reply.Message); } catch (RpcException ex) when(ex.StatusCode == StatusCode.DeadlineExceeded) { logger.LogError(ex, "Sending message timed out."); } } while (input != "quit") { ; } }