Esempio n. 1
0
        public static async Task DependendRequestsExample(Math.MathClient client)
        {
            var numbers = new List <Num>
            {
                new Num {
                    Num_ = 1
                },
                new Num {
                    Num_ = 2
                },
                new Num {
                    Num_ = 3
                }
            };

            Num sum;

            using (var sumCall = client.Sum())
            {
                await sumCall.RequestStream.WriteAllAsync(numbers);

                sum = await sumCall.ResponseAsync;
            }

            DivReply result = await client.DivAsync(new DivArgs { Dividend = sum.Num_, Divisor = numbers.Count });

            Console.WriteLine("Avg Result: " + result);
        }
Esempio n. 2
0
 /// <summary>
 /// Shows how to handle a call ending with non-OK status.
 /// </summary>
 public static async Task HandleErrorExample(Math.MathClient client)
 {
     try
     {
         DivReply result = await client.DivAsync(new DivArgs { Dividend = 5, Divisor = 0 });
     }
     catch (RpcException ex)
     {
         Console.WriteLine(string.Format("RPC ended with status {0}", ex.Status));
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Shows how to send request headers and how to access response headers
        /// and response trailers.
        /// </summary>
        public static async Task MetadataExample(Math.MathClient client)
        {
            var requestHeaders = new Metadata
            {
                { "custom-header", "custom-value" }
            };

            var call = client.DivAsync(new DivArgs {
                Dividend = 5, Divisor = 0
            }, requestHeaders);

            // Get response headers
            Metadata responseHeaders = await call.ResponseHeadersAsync;

            var result = await call;

            // Get response trailers after the call has finished.
            Metadata responseTrailers = call.GetTrailers();
        }
Esempio n. 4
0
        public static async Task DivAsyncExample(Math.MathClient client)
        {
            DivReply result = await client.DivAsync(new DivArgs { Dividend = 4, Divisor = 5 });

            Console.WriteLine("DivAsync Result: " + result);
        }