Beispiel #1
0
        private void StartButton_Click(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;

            if (button == null)
            {
                return;
            }
            try
            {
                if (Queryservice.IsUrl())
                {
                    httpserver = new HproseHttpListenerServer(Queryservice.GetUrl());
                    httpserver.Methods.AddInstanceMethods(Queryservice);
                    httpserver.Methods.AddInstanceMethods(new MainWindow());

                    httpserver.IsDebugEnabled = true;
                    httpserver.Start();
                    ListBoxServerMsg.Items.Insert(0, "服务启动成功:" + DateTime.Now.ToString());
                    //this.Queryservice.ServerMsg = "服务启动成功";
                    button.IsEnabled     = false;
                    StopButton.IsEnabled = true;
                }
                //}
                //else
                //{
                //    MessageBox.Show("请输入正确的服务器IP或者端口!");
                //}
            }
            catch (Exception ex)
            {
                ListBoxServerMsg.Items.Insert(0, "服务启动错误:" + ex.Message);
                // MessageBox.Show(ex.Message);
            }
        }
Beispiel #2
0
        private void StartHttpButton_Click(object sender, RoutedEventArgs e)
        {
            if (!(sender is Button button))
            {
                return;
            }
            try
            {
                var httpUrl = Queryservice.GetHttpUri();
                HttpServer = new HproseHttpListenerServer(httpUrl);
                HttpServer.Add("Expjson", enQrCodeService);
                HttpServer.Add("Encoder", enQrCodeService);
                HttpServer.Start();

                HttpServer.OnAfterInvoke += TcpServer_OnAfterInvoke;

                ListBoxServerMsg.Items.Insert(0, "Http服务启动成功:" + DateTime.Now.ToString());

                button.IsEnabled         = false;
                StopHttpButton.IsEnabled = true;
            }
            catch (Exception ex)
            {
                ListBoxServerMsg.Items.Insert(0, "Http服务启动错误:" + ex.Message);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 启动服务
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StartButton_Click(object sender, RoutedEventArgs e)
        {
            hpptserver = new HproseHttpListenerServer(txbServerIP.Text);
            hpptserver.Methods.AddInstanceMethods(new Queryservice());
            // hpptserver.Methods.AddInstanceMethods(new PDAServer());

            hpptserver.IsDebugEnabled = true;
            hpptserver.Start();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            HproseHttpListenerServer server = new HproseHttpListenerServer("http://localhost:2012/");
            TestService ts = new TestService();

            server.Add("Hello", ts);
            server.IsCrossDomainEnabled = true;
            //server.CrossDomainXmlFile = "crossdomain.xml";
            server.Start();
            Console.WriteLine("Server started.");
            Console.ReadLine();
            Console.WriteLine("Server stopped.");
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            ClassManager.Register(typeof(User), "User");
            HproseHttpListenerServer server = new HproseHttpListenerServer("http://localhost:2012/");

            server.Methods.AddInstanceMethods(new TestService());
            server.IsCrossDomainEnabled = true;
            server.CrossDomainXmlFile   = "crossdomain.xml";
            server.Start();
            Console.WriteLine("Server started.");
            Console.ReadLine();
            Console.WriteLine("Server stopped.");
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            HproseTcpListenerServer tcpserver = new HproseTcpListenerServer("tcp4://127.0.0.1:4321/");

            tcpserver.Add("Hello", typeof(Program));
            tcpserver.Start();
            HproseHttpListenerServer httpserver = new HproseHttpListenerServer("http://localhost:8888/");

            httpserver.Add("Hello", typeof(Program));
            httpserver.Start();
            Console.ReadKey();
            tcpserver.Stop();
            httpserver.Stop();
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            HproseClassManager.Register(typeof(User), "User");
            HproseHttpListenerServer server = new HproseHttpListenerServer("http://localhost:2018/");

            server.ThreadCount = 5000;

            TestService ts = new TestService();

            server.Add("Hello", ts, true);
            server.Add("SendUsers", ts);
            server.IsCrossDomainEnabled = true;
            //server.CrossDomainXmlFile = "crossdomain.xml";
            server.Start();
            Console.WriteLine("Server started.");
            Console.ReadLine();
            Console.WriteLine("Server stopped.");
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            //HproseClassManager.Register(typeof(User), "User");
            HproseHttpListenerServer server = new HproseHttpListenerServer("http://127.0.0.1:2012/");

            using (ThreadScopedLifestyle.BeginScope(container))
            {
                var registryService = container.GetInstance <IRegistryService>();
                registryService.Register(new RPC.Common.RpcService {
                    Name = "UserService", Host = "127.0.0.1", Port = 2012
                });
                registryService.Register(new RPC.Common.RpcService {
                    Name = Global.TraefikServiceName, Host = "127.0.0.1", Port = 82
                });                                                                                                                     //注册一个Traefik服务
                server.RegisterService <IUserService>(container.GetInstance <IUserService>());
            }
            server.IsCrossDomainEnabled = true;

            //server.CrossDomainXmlFile = "crossdomain.xml";
            server.Start();
            Console.WriteLine("Server started.");
            Console.ReadLine();
            Console.WriteLine("Server stopped.");
        }
Beispiel #9
0
        static void Main(string[] args)
        {
#if !DEBUG
            server = new HproseHttpListenerServer("http://114.215.253.25:22012/");
#else
            server = new HproseHttpListenerServer("http://127.0.0.1:22012/");
#endif
            Mongo Db = new Mongo("TaiDong");
            //Db.DeleteMany<User>(add=>true);
            // Db.Delete<Content>(a=>a.type=="about");
            //var add= Db.FindList<Content>(a => true);
            var AddDomian = new string[] { "TaiDong" };

            if (Db.Count <User>(a => true) == 0)
            {
                Db.Insert <User>(new User {
                    name = "admin", pass = "******", level = "管理员"
                });
            }

            var fs = Directory.GetFiles(dPath, "*.dll");
            foreach (var f in fs)
            {
                var fn = Path.GetFileName(f);
                try
                {
                    var aes = Assembly.LoadFile(f);
                    var ts  = aes.GetTypes();
                    foreach (var t in ts)
                    {
                        if (t.IsNotPublic)
                        {
                            continue;
                        }
                        if (t.Name.ToLower().EndsWith("model"))
                        {
                            HproseClassManager.Register(t, t.Name);
                        }
                        else
                        {
                            AddClass(t);
                        }
                    }
                }
                catch { }
            }

            try
            {
                var aes = Assembly.GetExecutingAssembly();
                var ts  = aes.GetTypes();
                foreach (var t in ts)
                {
                    if (t.IsNotPublic || AddDomian.All(a => !t.FullName.Contains(a)))
                    {
                        continue;
                    }
                    if (t.Name.ToLower().EndsWith("model"))
                    {
                        HproseClassManager.Register(t, t.Name);
                    }
                    else
                    {
                        AddClass(t);
                    }
                }
            }
            catch { }

            server.OnBeforeInvoke += (name, arg, byRef, context) =>
            {
                if (SaveFunc.Contains(name))
                {
                    if (arg.Length <= 0 || Token != arg[0] as string)
                    {
                        throw new Exception("验证失败!");
                    }
                }
                else if (UserSaveFunc.Contains(name))
                {
                    if (arg.Length <= 0 || !UserToken.ContainsValue(arg[0] as string))
                    {
                        throw new Exception("验证失败!");
                    }
                }
            };
            server.IsCrossDomainEnabled = true;
            //server.CrossDomainXmlFile = "crossdomain.xml";
            server.Start();
            Console.WriteLine("Server started.");
            Console.ReadLine();
            Console.WriteLine("Server stopped.");
        }