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

            Num sum;
            using (var sumCall = client.Sum())
            {
                await sumCall.RequestStream.WriteAll(numbers);
                sum = await sumCall.Result;
            }

            DivReply result = await client.DivAsync(new DivArgs.Builder { Dividend = sum.Num_, Divisor = numbers.Count }.Build());
            Console.WriteLine("Avg Result: " + result);
        }
Esempio n. 2
0
 public static async Task DivAsyncExample(Math.IMathClient client)
 {
     Task<DivReply> resultTask = client.DivAsync(new DivArgs.Builder { Dividend = 4, Divisor = 5 }.Build());
     DivReply result = await resultTask;
     Console.WriteLine("DivAsync Result: " + result);
 }
        /// <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();
        }
 public static async Task DivAsyncExample(Math.MathClient client)
 {
     DivReply result = await client.DivAsync(new DivArgs { Dividend = 4, Divisor = 5 });
     Console.WriteLine("DivAsync Result: " + result);
 }
 /// <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));
     }
 }