User Tools

Site Tools

blog:2019-07-02_grpc_for_c_note



2019-07-02 gRPC for C# Note

  • gRPC for C# setting

Install Packages in Project

  • On Project → Right Click, Select “Manage NuGet Packages…”
  • Install Packages
    • Grpc
    • Crpc.Core
    • Grpc.Tools
    • Grpc.Core.Api
    • Google.apis
    • Google.Cloud.Language.V1

Misc Codes

  • This code will assume server is available.
    var reply = client.SayHello(new HelloRequest { Name = user });
  • This code will block if server not response until server become available.
    var reply = client.SayHello(new HelloRequest { Name = user }, new CallOptions().WithWaitForReady(true));
  • Refer Example #1 in [8]. This code set a timeout duration 100000 ticks.
                    var callOptions = new CallOptions()
                    .WithDeadline(DateTime.UtcNow.AddTicks(100000))
                    .WithHeaders(Metadata.Empty);
    
                    Channel channel = new Channel(comboBox_RemoteIp.Text + ":" + comboBox_RemotePort.Text
                                            , ChannelCredentials.Insecure);
                    var client = new Greeter.GreeterClient(channel);
                    String user = "JK";
                    var reply = client.SayHello(new HelloRequest { Name = user }, callOptions);

References

TAGS

  • 419 person(s) visited this page until now.

Permalink blog/2019-07-02_grpc_for_c_note.txt · Last modified: 2019/07/02 10:25 by jethro

oeffentlich