Пример #1
0
 static async Task NoStream(TypicalGrpcClient client)
 {
     var req = new Request1
     {
         Req1Id     = 1,
         Req1Name   = "杨彦钢",
         Req1Inner1 = new InnerObj1 {
             Name = "yyg"
         }
     };
     var r = await client.NoStreamAsync(req);
 }
Пример #2
0
        static async Task  ServerStream(TypicalGrpcClient client)
        {
            var req = new Request1
            {
                Req1Id     = 1,
                Req1Name   = "杨彦钢",
                Req1Inner1 = new InnerObj1 {
                    Name = "yyg"
                }
            };
            var call = client.ServerStream(req);


            await foreach (var r in call.ResponseStream.ReadAllAsync())
            {
                System.Console.WriteLine($"id:{r.Rep1Id},name:{r.Rep1Name}");
            }
        }
Пример #3
0
        static async Task ClientStream(TypicalGrpcClient client)
        {
            var call = client.ClientStream();


            for (var i = 1; i <= 100; i++)
            {
                var req = new Request1
                {
                    Req1Id     = i,
                    Req1Name   = $"杨彦钢_{i}",
                    Req1Inner1 = new InnerObj1 {
                        Name = $"yyg_{i}"
                    }
                };

                await call.RequestStream.WriteAsync(req);
            }

            await call.RequestStream.CompleteAsync();//请求参数传送完毕,必须关闭该请求流

            var r = await call;
        }
Пример #4
0
 static void NoStreamNoParam(TypicalGrpcClient client)
 {
     var r = client.NoStreamNoParam(new Empty());
 }