当前位置: 首页>>代码示例>>C#>>正文


C# Core.Channel类代码示例

本文整理汇总了C#中Grpc.Core.Channel的典型用法代码示例。如果您正苦于以下问题:C# Channel类的具体用法?C# Channel怎么用?C# Channel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Channel类属于Grpc.Core命名空间,在下文中一共展示了Channel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Target

 public void Target()
 {
     using (var channel = new Channel("127.0.0.1", Credentials.Insecure))
     {
         Assert.IsTrue(channel.Target.Contains("127.0.0.1"));
     }
 }
开发者ID:ksophocleous,项目名称:grpc,代码行数:7,代码来源:ChannelTest.cs

示例2: Init

 public void Init()
 {
     var marshaller = new Marshaller<string>(
         (str) =>
         {
             if (str == "UNSERIALIZABLE_VALUE")
             {
                 // Google.Protobuf throws exception inherited from IOException
                 throw new IOException("Error serializing the message.");
             }
             return System.Text.Encoding.UTF8.GetBytes(str); 
         },
         (payload) =>
         {
             var s = System.Text.Encoding.UTF8.GetString(payload);
             if (s == "UNPARSEABLE_VALUE")
             {
                 // Google.Protobuf throws exception inherited from IOException
                 throw new IOException("Error parsing the message.");
             }
             return s;
         });
     helper = new MockServiceHelper(Host, marshaller);
     server = helper.GetServer();
     server.Start();
     channel = helper.GetChannel();
 }
开发者ID:xianglinghui,项目名称:grpc,代码行数:27,代码来源:MarshallingErrorsTest.cs

示例3: ConnectAsync

        public static async Task<WalletClient> ConnectAsync(string networkAddress, string rootCertificate)
        {
            if (networkAddress == null)
                throw new ArgumentNullException(nameof(networkAddress));
            if (rootCertificate == null)
                throw new ArgumentNullException(nameof(rootCertificate));

            var channel = new Channel(networkAddress, new SslCredentials(rootCertificate));
            var deadline = DateTime.UtcNow.AddSeconds(3);
            try
            {
                await channel.ConnectAsync(deadline);
            }
            catch (TaskCanceledException)
            {
                await channel.ShutdownAsync();
                throw new ConnectTimeoutException();
            }

            // Ensure the server is running a compatible version.
            var versionClient = new VersionService.VersionServiceClient(channel);
            var response = await versionClient.VersionAsync(new VersionRequest(), deadline: deadline);
            var serverVersion = new SemanticVersion(response.Major, response.Minor, response.Patch);
            SemanticVersion.AssertCompatible(RequiredRpcServerVersion, serverVersion);

            return new WalletClient(channel);
        }
开发者ID:decred,项目名称:Paymetheus,代码行数:27,代码来源:WalletClient.cs

示例4: Init

        public void Init()
        {
            var rootCert = File.ReadAllText(TestCredentials.ClientCertAuthorityPath);
            var keyCertPair = new KeyCertificatePair(
                File.ReadAllText(TestCredentials.ServerCertChainPath),
                File.ReadAllText(TestCredentials.ServerPrivateKeyPath));

            var serverCredentials = new SslServerCredentials(new[] { keyCertPair }, rootCert, true);
            var clientCredentials = new SslCredentials(rootCert, keyCertPair);

            server = new Server
            {
                Services = { TestService.BindService(new TestServiceImpl()) },
                Ports = { { Host, ServerPort.PickUnused, serverCredentials } }
            };
            server.Start();

            var options = new List<ChannelOption>
            {
                new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride)
            };

            channel = new Channel(Host, server.Ports.Single().BoundPort, clientCredentials, options);
            client = TestService.NewClient(channel);
        }
开发者ID:rwightman,项目名称:grpc,代码行数:25,代码来源:SslCredentialsTest.cs

示例5: Main

        static void Main(string[] args)
        {
            var rpcChannel = new Channel("localhost:1337", ChannelCredentials.Insecure);
            var rpcClient = new BenchmarkServiceClient(BenchmarkService.NewClient(rpcChannel));
            rpcChannel.ConnectAsync().Wait();

            _timer.Elapsed += (s, e) =>
            {
                var lastMinuteCallCount = Interlocked.Exchange(ref _lastMinuteCallCount, 0);
                Console.WriteLine($"{DateTime.Now} -- {lastMinuteCallCount} ops/sec");
            };
            _timer.Start();

            for (int i = 0; i < CALL_COUNT; i++)
            {
                rpcClient.Operation(new ServiceRequest { Id = 10 });
                Interlocked.Increment(ref _lastMinuteCallCount);
            }

            //for (int i = 0; i < CALL_COUNT; i++)
            //{
            //    rpcClient.OperationAsync(new ServiceRequest { Id = 10 }).ContinueWith(t => Interlocked.Increment(ref _lastMinuteCallCount));
            //}

            //rpcClient.OperationStreamAsync(() => Interlocked.Increment(ref _lastMinuteCallCount)).Wait();
        }
开发者ID:mleenhardt,项目名称:rpc-benchmark,代码行数:26,代码来源:Program.cs

示例6: Init

        public void Init()
        {
            var serverCredentials = new SslServerCredentials(new[] { new KeyCertificatePair(File.ReadAllText(TestCredentials.ServerCertChainPath), File.ReadAllText(TestCredentials.ServerPrivateKeyPath)) });
            server = new Server
            {
                Services = { TestService.BindService(new TestServiceImpl()) },
                Ports = { { Host, ServerPort.PickUnused, serverCredentials } }
            };
            server.Start();

            var options = new List<ChannelOption>
            {
                new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride)
            };

            var asyncAuthInterceptor = new AsyncAuthInterceptor(async (authUri, metadata) =>
            {
                await Task.Delay(100);  // make sure the operation is asynchronous.
                metadata.Add("authorization", "SECRET_TOKEN");
            });

            var clientCredentials = ChannelCredentials.Create(
                new SslCredentials(File.ReadAllText(TestCredentials.ClientCertAuthorityPath)),
                new MetadataCredentials(asyncAuthInterceptor));
            channel = new Channel(Host, server.Ports.Single().BoundPort, clientCredentials, options);
            client = TestService.NewClient(channel);
        }
开发者ID:nkibler,项目名称:grpc,代码行数:27,代码来源:MetadataCredentialsTest.cs

示例7: Init

 public void Init()
 {
     helper = new MockServiceHelper(Host);
     server = helper.GetServer();
     server.Start();
     channel = helper.GetChannel();
 }
开发者ID:larsonmpdx,项目名称:grpc,代码行数:7,代码来源:ShutdownTest.cs

示例8: WaitForStateChangedAsync_InvalidArgument

 public void WaitForStateChangedAsync_InvalidArgument()
 {
     using (var channel = new Channel("localhost", Credentials.Insecure))
     {
         Assert.Throws(typeof(ArgumentException), () => channel.WaitForStateChangedAsync(ChannelState.FatalFailure));
     }
 }
开发者ID:hongweiwang,项目名称:grpc,代码行数:7,代码来源:ChannelTest.cs

示例9: State_IdleAfterCreation

 public void State_IdleAfterCreation()
 {
     using (var channel = new Channel("localhost", Credentials.Insecure))
     {
         Assert.AreEqual(ChannelState.Idle, channel.State);
     }
 }
开发者ID:ksophocleous,项目名称:grpc,代码行数:7,代码来源:ChannelTest.cs

示例10: Main

        private const string ProjectName = "apiarydotnetclienttesting"; // this is actually gRPC, but I had that project handy

        #endregion Fields

        #region Methods

        static void Main(string[] args)
        {
            // Prerequisites
            // 1. create a new cloud project with your google account
            // 2. enable cloud datastore API on that project
            // 3. 'gcloud auth login' to store your google credential in a well known location (from where GoogleCredential.GetApplicationDefaultAsync() can pick it up).

            var credentials = Task.Run(() => GoogleCredential.GetApplicationDefaultAsync()).Result;

            Channel channel = new Channel("datastore.googleapis.com", credentials.ToChannelCredentials());

            var datastoreClient = new Google.Datastore.V1Beta3.Datastore.DatastoreClient(channel);

            var result = datastoreClient.RunQuery(new RunQueryRequest
            {
                ProjectId = ProjectName,
                GqlQuery = new GqlQuery {
                    QueryString = "SELECT * FROM Foo"
                }
            });

            Console.WriteLine(result);

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();

            channel.ShutdownAsync();
        }
开发者ID:jtattermusch,项目名称:grpc-samples-unofficial,代码行数:34,代码来源:Program.cs

示例11: Init

 public void Init()
 {
     server = new Server();
     server.AddServiceDefinition(ServiceDefinition);
     int port = server.AddPort(Host, Server.PickUnusedPort, ServerCredentials.Insecure);
     server.Start();
     channel = new Channel(Host, port, Credentials.Insecure);
 }
开发者ID:simonkuang,项目名称:grpc,代码行数:8,代码来源:ClientServerTest.cs

示例12: Init

 public void Init()
 {
     server = new Server();
     server.AddServiceDefinition(ServiceDefinition);
     int port = server.AddListeningPort(Host, Server.PickUnusedPort);
     server.Start();
     channel = new Channel(Host, port);
 }
开发者ID:meisterpeeps,项目名称:grpc,代码行数:8,代码来源:ClientServerTest.cs

示例13: Main

 public static void Main(string[] args)
 {
     // This code doesn't do much but makes sure the native extension is loaded
     // which is what we are testing here.
     Channel c = new Channel("127.0.0.1:1000", ChannelCredentials.Insecure);
     c.ShutdownAsync().Wait();
     Console.WriteLine("Success!");
 }
开发者ID:kriswuollett,项目名称:grpc,代码行数:8,代码来源:Program.cs

示例14: Main

 static void Main(string[] args)
 {
     var channel = new Channel("127.0.0.1:9007", ChannelCredentials.Insecure);
     var client = new gRPC.gRPCClient(channel);
     var replay = client.SayHello(new HelloRequest { Name = "shoy" });
     Console.WriteLine(replay.Message);
     channel.ShutdownAsync().Wait();
     Console.ReadKey();
 }
开发者ID:shoy160,项目名称:Shoy.Common,代码行数:9,代码来源:Program.cs

示例15: Init

        public void Init()
        {
            server = new Server();
            server.AddServiceDefinition(ServiceDefinition);
            int port = server.AddPort(Host, Server.PickUnusedPort, ServerCredentials.Insecure);
            server.Start();
            channel = new Channel(Host, port, Credentials.Insecure);

            stringFromServerHandlerTcs = new TaskCompletionSource<string>();
        }
开发者ID:ksophocleous,项目名称:grpc,代码行数:10,代码来源:TimeoutsTest.cs


注:本文中的Grpc.Core.Channel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。