public void Init() { server = new Server(); server.AddServiceDefinition(ServiceDefinition); int port = server.AddListeningPort(Host, Server.PickUnusedPort); server.Start(); channel = new Channel(Host, port); }
public void StartAndShutdownServer() { Server server = new Server(); server.AddListeningPort("localhost", Server.PickUnusedPort); server.Start(); server.ShutdownAsync().Wait(); GrpcEnvironment.Shutdown(); }
public void StartAndShutdownServer() { GrpcEnvironment.Initialize(); Server server = new Server(); server.AddListeningPort("localhost:0"); server.Start(); server.ShutdownAsync().Wait(); GrpcEnvironment.Shutdown(); }
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); }
public static void Main(string[] args) { GrpcEnvironment.Initialize(); Server server = new Server(); server.AddServiceDefinition(Greeter.BindService(new GreeterImpl())); int port = server.AddListeningPort("localhost", 50051); server.Start(); Console.WriteLine("Greeter server listening on port " + port); Console.WriteLine("Press any key to stop the server..."); Console.ReadKey(); server.ShutdownAsync().Wait(); GrpcEnvironment.Shutdown(); }
public static void Main(string[] args) { string host = "0.0.0.0"; Server server = new Server(); server.AddServiceDefinition(Math.BindService(new MathServiceImpl())); int port = server.AddListeningPort(host, 23456); server.Start(); Console.WriteLine("MathServer listening on port " + port); Console.WriteLine("Press any key to stop the server..."); Console.ReadKey(); server.ShutdownAsync().Wait(); GrpcEnvironment.Shutdown(); }
static void Main(string[] args) { var features = RouteGuideUtil.ParseFeatures(RouteGuideUtil.DefaultFeaturesFile); GrpcEnvironment.Initialize(); Server server = new Server(); server.AddServiceDefinition(RouteGuide.BindService(new RouteGuideImpl(features))); int port = server.AddListeningPort("localhost", 50052); server.Start(); Console.WriteLine("RouteGuide server listening on port " + port); Console.WriteLine("Press any key to stop the server..."); Console.ReadKey(); server.ShutdownAsync().Wait(); GrpcEnvironment.Shutdown(); }
public void UnaryCall() { Server server = new Server(); server.AddServiceDefinition( ServerServiceDefinition.CreateBuilder(serviceName) .AddMethod(unaryEchoStringMethod, HandleUnaryEchoString).Build()); int port = server.AddListeningPort(host + ":0"); server.Start(); using (Channel channel = new Channel(host + ":" + port)) { var call = new Call<string, string>(serviceName, unaryEchoStringMethod, channel, Metadata.Empty); Assert.AreEqual("ABC", Calls.BlockingUnaryCall(call, "ABC", default(CancellationToken))); Assert.AreEqual("abcdef", Calls.BlockingUnaryCall(call, "abcdef", default(CancellationToken))); } server.ShutdownAsync().Wait(); }
public void Init() { GrpcEnvironment.Initialize(); server = new Server(); server.AddServiceDefinition(TestService.BindService(new TestServiceImpl())); int port = server.AddListeningPort(host, Server.PickUnusedPort, TestCredentials.CreateTestServerCredentials()); server.Start(); var options = new List<ChannelOption> { new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride) }; channel = new Channel(host, port, TestCredentials.CreateTestClientCredentials(true), options); client = TestService.NewStub(channel); }
public void Init() { GrpcEnvironment.Initialize(); server = new Server(); server.AddServiceDefinition(TestService.BindService(new TestServiceImpl())); int port = server.AddListeningPort(host, Server.PickUnusedPort, TestCredentials.CreateTestServerCredentials()); server.Start(); var channelArgs = ChannelArgs.CreateBuilder() .AddString(ChannelArgs.SslTargetNameOverrideKey, TestCredentials.DefaultHostOverride).Build(); channel = new Channel(host + ":" + port, TestCredentials.CreateTestClientCredentials(true), channelArgs); client = TestService.NewStub(channel); }
public void Init() { GrpcEnvironment.Initialize(); server = new Server(); server.AddServiceDefinition(Math.BindService(new MathServiceImpl())); int port = server.AddListeningPort(host, Server.PickUnusedPort); server.Start(); channel = new Channel(host + ":" + port); // TODO(jtattermusch): get rid of the custom header here once we have dedicated tests // for header support. var stubConfig = new StubConfiguration((headerBuilder) => { headerBuilder.Add(new Metadata.MetadataEntry("customHeader", "abcdef")); }); client = Math.NewStub(channel, stubConfig); }
private void Run() { var server = new Server(); server.AddServiceDefinition(TestService.BindService(new TestServiceImpl())); string host = "0.0.0.0"; int port = options.port.Value; if (options.useTls) { server.AddListeningPort(host, port, TestCredentials.CreateTestServerCredentials()); } else { server.AddListeningPort(host, options.port.Value); } Console.WriteLine("Running server on " + string.Format("{0}:{1}", host, port)); server.Start(); server.ShutdownTask.Wait(); GrpcEnvironment.Shutdown(); }
public void Init() { server = new Server(); server.AddServiceDefinition(Math.BindService(new MathServiceImpl())); int port = server.AddListeningPort(host, Server.PickUnusedPort); server.Start(); channel = new Channel(host, port); client = Math.NewClient(channel); // TODO(jtattermusch): get rid of the custom header here once we have dedicated tests // for header support. client.HeaderInterceptor = (metadata) => { metadata.Add(new Metadata.Entry("customHeader", "abcdef")); }; }
private void Run() { GrpcEnvironment.Initialize(); var server = new Server(); server.AddServiceDefinition(TestServiceGrpc.BindService(new TestServiceImpl())); string addr = "0.0.0.0:" + options.port; if (options.useTls) { server.AddListeningPort(addr, TestCredentials.CreateTestServerCredentials()); } else { server.AddListeningPort(addr); } Console.WriteLine("Running server on " + addr); server.Start(); server.ShutdownTask.Wait(); GrpcEnvironment.Shutdown(); }
public void UnaryCallPerformance() { Server server = new Server(); server.AddServiceDefinition( ServerServiceDefinition.CreateBuilder(serviceName) .AddMethod(unaryEchoStringMethod, HandleUnaryEchoString).Build()); int port = server.AddListeningPort(host + ":0"); server.Start(); using (Channel channel = new Channel(host + ":" + port)) { var call = new Call<string, string>(serviceName, unaryEchoStringMethod, channel, Metadata.Empty); BenchmarkUtil.RunBenchmark(100, 1000, () => { Calls.BlockingUnaryCall(call, "ABC", default(CancellationToken)); }); } server.ShutdownAsync().Wait(); }
public void UnknownMethodHandler() { Server server = new Server(); server.AddServiceDefinition( ServerServiceDefinition.CreateBuilder(serviceName).Build()); int port = server.AddListeningPort(host + ":0"); server.Start(); using (Channel channel = new Channel(host + ":" + port)) { var call = new Call<string, string>(serviceName, unaryEchoStringMethod, channel, Metadata.Empty); try { Calls.BlockingUnaryCall(call, "ABC", default(CancellationToken)); Assert.Fail(); } catch (RpcException e) { Assert.AreEqual(StatusCode.Unimplemented, e.Status.StatusCode); } } server.ShutdownAsync().Wait(); }