Beispiel #1
0
        /// <summary>
        /// Starts the specified service.
        /// </summary>
        /// <param name="serverInterceptor">The server interceptor.</param>
        /// <returns>A tuple.</returns>
        public static DisposableServer Start(Interceptor serverInterceptor = null)
        {
            // Disable SO_REUSEPORT to prevent https://github.com/grpc/grpc/issues/10755
            var serviceDefinition = Foobar.BindService(new FoobarService());

            if (serverInterceptor != null)
            {
                serviceDefinition = serviceDefinition.Intercept(serverInterceptor);
            }

            var server = new Server
            {
                Ports    = { { "localhost", ServerPort.PickUnused, ServerCredentials.Insecure } },
                Services = { serviceDefinition },
            };

            server.Start();
            var serverUriString = new Uri("dns:localhost:" + server.Ports.Single().BoundPort).ToString();

            return(new DisposableServer(server, serverUriString));
        }