Пример #1
0
        static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    NetClient client = new NetClient("127.0.0.1", 8911);
                    client.Dispose();
                    break;
                }
                catch (Exception)
                {
                    Thread.Sleep(100);
                }
            }

            var gatewaycert = new System.Security.Cryptography.X509Certificates.X509Certificate2("../../../../pfx/client.pfx", "123456");

            ServiceCollection services = new ServiceCollection();

            var gateways = new NetAddress[] {
                new NetAddress {
                    Address = "localhost",
                    Port    = 8911
                }
            };
            var msp = new MicroServiceHost(services);


            var builder = new ConfigurationBuilder();

            builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false);
            var configuration = builder.Build();

            //services.UseJmsTokenAuthentication(AuthorizationContentType.String, "127.0.0.1", 9911,"auth");
            services.AddLogging(loggingBuilder =>
            {
                loggingBuilder.AddConfiguration(configuration.GetSection("Logging"));
                loggingBuilder.AddConsole(); // 将日志输出到控制台
            });
            services.AddSingleton <IConfiguration>(configuration);



            msp.Register <Controller1>("Controller1");
            msp.Register <Controller2>("Service2");
            msp.RegisterScheduleTask <AutoRun1>();
            msp.ServiceProviderBuilded += Msp_ServiceProviderBuilded;
            msp.Build(8912, gateways)
            .UseSSL(c =>
            {     //配置ssl
                c.GatewayClientCertificate = gatewaycert;
                c.ServerCertificate        = new X509Certificate2("../../../../pfx/service_server.pfx", "123456");
            })
            .Run();
        }
Пример #2
0
        static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    NetClient client = new NetClient("127.0.0.1", 8911);
                    client.Dispose();
                    break;
                }
                catch (Exception)
                {
                    Thread.Sleep(100);
                }
            }


            ServiceCollection services = new ServiceCollection();

            var gateways = new NetAddress[] {
                new NetAddress {
                    Address = "localhost",
                    Port    = 8911
                }
            };
            var msp = new MicroServiceHost(services);


            var builder = new ConfigurationBuilder();

            builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false);
            var configuration = builder.Build();

            //services.UseJmsTokenAuthentication(AuthorizationContentType.String, "127.0.0.1", 9911,"auth");
            services.AddLogging(loggingBuilder =>
            {
                loggingBuilder.AddConfiguration(configuration.GetSection("Logging"));
                loggingBuilder.AddConsole(); // 将日志输出到控制台
            });
            services.AddSingleton <IConfiguration>(configuration);


            msp.ClientCheckCode = @"
            try
            {
               var number = Convert.ToInt64(arg);
                return number > 0;
            }
            catch 
            {
            }
            return false;

";

            msp.Register <Controller1>("Controller1");
            msp.Register <Controller2>("Service2");
            msp.RegisterScheduleTask <AutoRun1>();
            msp.ServiceProviderBuilded += Msp_ServiceProviderBuilded;
            msp.Build(8912, gateways)
            .Run();
        }
Пример #3
0
        static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    NetClient client = new NetClient("127.0.0.1", 8911);
                    client.Dispose();
                    break;
                }
                catch (Exception)
                {
                    Thread.Sleep(100);
                }
            }

            var gatewaycert = new System.Security.Cryptography.X509Certificates.X509Certificate2("../../../../pfx/client.pfx", "123456");

            ServiceCollection services = new ServiceCollection();

            var gateways = new NetAddress[] {
                new NetAddress {
                    Address = "localhost",
                    Port    = 8911
                }
            };
            var msp = new MicroServiceHost(services);

            if (File.Exists("./appsettings.json") == false)
            {
                //本地没有appsettings.json,先从网关拉一个
                msp.GetGatewayShareFile(gateways[0], "test/appsettings.json", "./appsettings.json", gatewaycert);
            }


            var builder = new ConfigurationBuilder();

            builder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false);
            var configuration = builder.Build();


            services.AddLogging(loggingBuilder =>
            {
                loggingBuilder.AddConfiguration(configuration.GetSection("Logging"));
                loggingBuilder.AddConsole(); // 将日志输出到控制台
            });
            services.AddSingleton <IConfiguration>(configuration);

            msp.MapShareFileToLocal(gateways[0], "test/appsettings.json", "./appsettings.json", (p, p2) => {
                Console.WriteLine(p + "回调");
            });
            msp.MapShareFileToLocal(gateways[0], "test/appsettings2.json", "./appsettings2.json");


            msp.Register <Controller1>("Controller1");
            msp.Register <Controller2>("Service2");
            msp.RegisterScheduleTask <AutoRun>();
            msp.Build(8912, gateways)
            .UseSSL(c =>
            {     //配置ssl
                c.GatewayClientCertificate = gatewaycert;
                c.ServerCertificate        = new X509Certificate2("../../../../pfx/service_server.pfx", "123456");
            })
            .Run();
        }