static void Main(string[] args) { int port; try { port = 9000; // Hard code test if (port <= 0 || port > 65536) { throw new Exception(port + " is not a valid TCP port number."); } } catch (Exception ex) { Console.WriteLine("TCP port must be a positive number. Exception detail: " + ex.Message); return; } try { _serviceApplication = ScsServiceBuilder.CreateService(new ScsTcpEndPoint(port)); _msgService = new MsgService(); _serviceApplication.AddService <IMsgService, MsgService>(_msgService); _msgService.UserListChanged += msgService_UserListChanged; _serviceApplication.Start(); } catch (Exception ex) { Console.WriteLine("Service can not be started. Exception detail: " + ex.Message); return; } }
public static void Start(IConfigurationRoot config) { var builder = new ContainerBuilder(); builder.RegisterInstance(config).As <IConfigurationRoot>(); //builder.RegisterInstance(new DataContext(config)).As<IDataContext>(); //builder.RegisterAssemblyTypes(typeof(IDataContext).GetTypeInfo().Assembly).Where(t => t.Name.EndsWith("Repository")).AsImplementedInterfaces(); _container = builder.Build(); var servercert = File.ReadAllText(@"server.crt"); var serverkey = File.ReadAllText(@"server.key"); var keypair = new KeyCertificatePair(servercert, serverkey); var sslCredentials = new SslServerCredentials(new List <KeyCertificatePair>() { keypair }); var healthService = new HealthServiceImpl(); _server = new Grpc.Core.Server { Services = { MsgService.BindService(new MsgServiceImpl()), Grpc.Health.V1.Health.BindService(healthService) }, Ports = { new ServerPort("0.0.0.0", 9007, sslCredentials) } }; _server.Start(); healthService.SetStatus("Demo", Grpc.Health.V1.HealthCheckResponse.Types.ServingStatus.Serving); _server.ShutdownTask.Wait(); }