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


C# Server.Start方法代码示例

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


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

示例1: 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

示例2: Main

        static void Main(string[] args)
        {
            const int port = 1337;

            var serviceImpl = new PlaygroundServiceImpl(new PersonRepository());
            var server = new Grpc.Core.Server
            {
                Services = { PlaygroundService.BindService(serviceImpl) },
                Ports =
                {
                    new ServerPort("0.0.0.0", port, new SslServerCredentials(
                        new[]
                        {
                            new KeyCertificatePair(
                                File.ReadAllText("certificates\\server.crt"),
                                File.ReadAllText("certificates\\server.key"))
                        }))
                }
            };
            server.Start();

            Console.WriteLine("RPC server listening on port " + port);
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            serviceImpl.Shutdown();
            server.ShutdownAsync().Wait();
        }
开发者ID:mleenhardt,项目名称:grpc-playground,代码行数:28,代码来源:Program.cs

示例3: 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

示例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: Init

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

示例6: 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

示例7: StartAndShutdownServer

 public void StartAndShutdownServer()
 {
     Server server = new Server();
     server.AddListeningPort("localhost", Server.PickUnusedPort);
     server.Start();
     server.ShutdownAsync().Wait();
     GrpcEnvironment.Shutdown();
 }
开发者ID:hmings888,项目名称:grpc,代码行数:8,代码来源:ServerTest.cs

示例8: 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

示例9: StartAndShutdownServer

 public void StartAndShutdownServer()
 {
     Server server = new Server
     {
         Ports = { new ServerPort("localhost", ServerPort.PickUnused, ServerCredentials.Insecure) }
     };
     server.Start();
     server.ShutdownAsync().Wait();
 }
开发者ID:larsonmpdx,项目名称:grpc,代码行数:9,代码来源:ServerTest.cs

示例10: Init

        public void Init()
        {
            helper = new MockServiceHelper();

            server = helper.GetServer();
            server.Start();
            channel = helper.GetChannel();

            headers = new Metadata { { "ascii-header", "abcdefg" } };
        }
开发者ID:ConfusedReality,项目名称:pkg_network_grpc,代码行数:10,代码来源:ResponseHeadersTest.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);

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

示例12: Init

 public void Init()
 {
     server = new Server
     {
         Services = { Math.BindService(new MathServiceImpl()) },
         Ports = { { Host, ServerPort.PickUnused, ServerCredentials.Insecure } }
     };
     server.Start();
     channel = new Channel(Host, server.Ports.Single().BoundPort, Credentials.Insecure);
     client = Math.NewClient(channel);
 }
开发者ID:hongweiwang,项目名称:grpc,代码行数:11,代码来源:MathClientServerTests.cs

示例13: Init

 public void Init()
 {
     server = new Server
     {
         Services = { TestService.BindService(new UnimplementedTestServiceImpl()) },
         Ports = { { Host, ServerPort.PickUnused, SslServerCredentials.Insecure } }
     };
     server.Start();
     channel = new Channel(Host, server.Ports.Single().BoundPort, ChannelCredentials.Insecure);
     client = new TestService.TestServiceClient(channel);
 }
开发者ID:ConfusedReality,项目名称:pkg_network_grpc,代码行数:11,代码来源:GeneratedServiceBaseTest.cs

示例14: StartAndShutdownServer

        public void StartAndShutdownServer()
        {
            GrpcEnvironment.Initialize();

            Server server = new Server();
            server.AddListeningPort("localhost:0");
            server.Start();
            server.ShutdownAsync().Wait();

            GrpcEnvironment.Shutdown();
        }
开发者ID:jwatt,项目名称:kythe,代码行数:11,代码来源:ServerTest.cs

示例15: Init

        public void Init()
        {
            server = new Server
            {
                Services = { ServiceDefinition },
                Ports = { { Host, ServerPort.PickUnused, ServerCredentials.Insecure } }
            };
            server.Start();
            channel = new Channel(Host, server.Ports.Single().BoundPort, Credentials.Insecure);

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


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