static void Main(string[] args) { //from Grpc.Core Server server = null; try { //Grpc server instance with insecure connection on localhost //insecure as out client is also going to run on same machine //this is just for a demo purpose and real practice it will replaced by //meaningful entity server = new Server { Services = { ComputeAverageService.BindService(new ComputeAverageServiceEx()) }, Ports = { new ServerPort("localhost", serverPort, ServerCredentials.Insecure) } }; server.Start(); Console.WriteLine($"The server is actively listening on port {serverPort}..."); Console.ReadKey(); } catch (IOException ex) { Console.WriteLine($"Unable to start a server!\r\nMore details - {ex.Message}."); } finally { server?.ShutdownAsync().Wait(); } }
static void Main(string[] args) { Server server = null; try { server = new Server() { Services = { GreetingService.BindService(new GreetingServiceImpl()), SumService.BindService(new SumServiceImpl()), PrimeNumberService.BindService(new PrimeNumberServiceImpl()), ComputeAverageService.BindService(new ComputeAverageServiceImpl()), FindMaximumService.BindService(new FindMaximumServiceImpl()) }, Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) } }; server.Start(); Console.WriteLine("The server is listening on the port: " + Port); Console.ReadKey(); } catch (IOException e) { Console.WriteLine("The server failed to start: " + e.Message); throw; } finally { if (server != null) { server.ShutdownAsync().Wait(); } } }
static void Main(string[] args) { Server server = null; try { server = new Server() { Services = { ComputeAverageService.BindService(new ComputeAverageServiceImplementation()), ServerReflection.BindService(new ReflectionServiceImpl(new List <ServiceDescriptor>() { ComputeAverageService.Descriptor })) }, Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) } }; server.Start(); Console.WriteLine("The server is listening on the port: 50051"); Console.ReadKey(); } catch (IOException e) { Console.WriteLine($"Something went wrong - {e.Message}"); throw; } finally { if (server != null) { server.ShutdownAsync().Wait(); } } }