• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Core.Server类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

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


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


示例4: Init

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


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


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


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


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

 public ServerRpcNew(Server server, CallSafeHandle call, string method, string host, Timespec deadline, Metadata requestMetadata)
 {
     this.server = server;
     this.call = call;
     this.method = method;
     this.host = host;
     this.deadline = deadline;
     this.requestMetadata = requestMetadata;
 }
开发者ID:ConfusedReality,项目名称:pkg_network_grpc,代码行数:9,代码来源:ServerRpcNew.cs


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


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


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


示例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 = { 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


示例16: Init

        public void Init()
        {
            serviceImpl = new HealthServiceImpl();

            server = new Server();
            server.AddServiceDefinition(Grpc.Health.V1Alpha.Health.BindService(serviceImpl));
            int port = server.AddListeningPort(Host, Server.PickUnusedPort);
            server.Start();
            channel = new Channel(Host, port);

            client = Grpc.Health.V1Alpha.Health.NewClient(channel);
        }
开发者ID:hmings888,项目名称:grpc,代码行数:12,代码来源:HealthClientServerTest.cs


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


示例18: CannotModifyAfterStarted

        public void CannotModifyAfterStarted()
        {
            Server server = new Server
            {
                Ports = { new ServerPort("localhost", ServerPort.PickUnused, ServerCredentials.Insecure) }
            };
            server.Start();
            Assert.Throws(typeof(InvalidOperationException), () => server.Ports.Add("localhost", 9999, ServerCredentials.Insecure));
            Assert.Throws(typeof(InvalidOperationException), () => server.Services.Add(ServerServiceDefinition.CreateBuilder("serviceName").Build()));

            server.ShutdownAsync().Wait();
        }
开发者ID:larsonmpdx,项目名称:grpc,代码行数:12,代码来源:ServerTest.cs


示例19: Start

      public void Start(IServiceConfiguration configuration)
      {
        BioData.BioSkyNetRepository _database = _locator.GetProcessor<BioData.BioSkyNetRepository>();
        _server = new Server
        {
          Services = { BiometricDatabaseSevice.BindService(new BiometricDatabaseSeviceImpl(_database)) },
          Ports = { new ServerPort(configuration.IpAddress, configuration.Port, ServerCredentials.Insecure) }
        };
        _server.Start();

        Console.WriteLine("BiometricDatabaseSevice server listening on port " + configuration.Port);
        Console.WriteLine("Press any key to stop the server...");
    }
开发者ID:jackersson,项目名称:BioSky.Net.DatabaseService,代码行数:13,代码来源:BioServiceManager.cs


示例20: GetServerRpcNew

        // Gets data of server_rpc_new completion.
        public ServerRpcNew GetServerRpcNew(Server server)
        {
            var call = Native.grpcsharp_request_call_context_call(this);

            var method = Marshal.PtrToStringAnsi(Native.grpcsharp_request_call_context_method(this));
            var host = Marshal.PtrToStringAnsi(Native.grpcsharp_request_call_context_host(this));
            var deadline = Native.grpcsharp_request_call_context_deadline(this);

            IntPtr metadataArrayPtr = Native.grpcsharp_request_call_context_request_metadata(this);
            var metadata = MetadataArraySafeHandle.ReadMetadataFromPtrUnsafe(metadataArrayPtr);

            return new ServerRpcNew(server, call, method, host, deadline, metadata);
        }
开发者ID:nerdrew,项目名称:grpc,代码行数:14,代码来源:RequestCallContextSafeHandle.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Internal.BatchContextSafeHandle类代码示例发布时间:2022-05-26
下一篇:
C# Core.Metadata类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap