コード例 #1
0
        private async Task Example3(CancellationToken cancelToken = default)
        {
            using (var svc = new JsonRpcClient(SampleServerUri).AsServiceContract <ISampleService2>())
            {
                try
                {
                    var cts  = CancellationTokenSource.CreateLinkedTokenSource(cancelToken);
                    var res1 = await svc.Method3(cts.Token).CancelAfter(5000, cts).ConfigureAwait(false);
                }
                catch (TimeoutException)
                {
                    Console.WriteLine("Operation timed out...");
                }
                catch (JsonRpcRequestException x)
                {
                    Console.WriteLine($"StatusCode = {x.StatusCode}, details = {x.ToString()}");
                }
                catch (Exception x)
                {
                    Console.WriteLine(x.Message);
                }

                await svc.Method4().ConfigureAwait(false);

                await svc.Method5("Test123").ConfigureAwait(false);
            }
        }