Exemplo n.º 1
0
 private void StartTcpButton_Click(object sender, RoutedEventArgs e)
 {
     if (!(sender is Button button))
     {
         return;
     }
     try
     {
         if (Queryservice.IsUrl())
         {
             TcpServer = new HproseTcpListenerServer(Queryservice.GetTcpUrl());
             TcpServer.Add("Expjson", enQrCodeService);
             TcpServer.Add("Encoder", enQrCodeService);
             TcpServer.OnAfterInvoke += TcpServer_OnAfterInvoke;
             TcpServer.Start();
             //HproseTcpListenerServer = new HproseTcpListenerServer(Queryservice.GetTpcUrl());
             //HproseTcpListenerServer.AddMissingMethod("GetLogistinInfo",this);
             //HproseTcpListenerServer.Start();
             ListBoxServerMsg.Items.Insert(0, "Tcp服务启动成功:" + DateTime.Now.ToString());
             // this.Queryservice.ServerMsg = "服务启动成功";
             button.IsEnabled        = false;
             StopTcpButton.IsEnabled = true;
         }
     }
     catch (Exception ex)
     {
         ListBoxServerMsg.Items.Insert(0, "Tcp服务启动错误:" + ex.Message);
         // MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            HproseTcpListenerServer tcpserver = new HproseTcpListenerServer("tcp4://127.0.0.1:4321/");

            tcpserver.Filter = new MyServerFilter();
            tcpserver.Add("Inc", typeof(Program));
            tcpserver.Start();
            Console.ReadKey();
            tcpserver.Stop();
        }
Exemplo n.º 3
0
 protected override void OnStart(string[] args)
 {
     RPC.Add(WORK);
     RPC.Start();
     //while (!Debugger.IsAttached)
     "服务正常打开".WriteSysLog();
     {
         Thread.Sleep(100);
     }
     WORK.DoWork2("TL_LoginTrade", "");
     DoWork();
 }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
        public static void Start()
        {
            int parse_traceMilliseconds;

            traceMilliseconds = int.TryParse(ConfigurationManager.AppSettings["traceMilliseconds"], out parse_traceMilliseconds) ? parse_traceMilliseconds : default(int?);
            string[] allowSecretKeys = ConfigurationManager.AppSettings["allowSecretKeys"].Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            isConsole = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle != IntPtr.Zero;
            tcpserver = new HproseTcpListenerServer(string.Format("tcp4://{0}/", ipPort));
            writeLog(string.Format("开始监听{0}", ipPort));
            //服务dll所在文件夹:/bin/ServiceCores/xxx
            string directoryPath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, startServicesFolder);

            if (!Directory.Exists(directoryPath))
            {
                writeLog("服务dll文件夹不存在");
                return;
            }
            writeLog(string.Format("开始加载{0}目录下服务", startServicesFolder));
            var services = new List <string>();

            string[] files = Directory.GetFiles(directoryPath);
            try
            {
                ProxyDomain pd = new ProxyDomain();
                foreach (var fullName in files)
                {
                    // Path.GetExtension(fileName).Equals(".dll")
                    if (fullName.ToLower().EndsWith("core.dll"))
                    {
                        string fileName = Path.GetFileNameWithoutExtension(fullName);
                        //byte[] buffer = File.ReadAllBytes(fullName);
                        //var ass = Assembly.Load(buffer);
                        var ass = pd.GetAssembly(fullName);
                        foreach (Type t in ass.GetExportedTypes())
                        {
                            if (t.IsClass && t.Namespace.EndsWith("Services"))
                            {
                                if (services.Contains(t.Name.ToLower()))
                                {
                                    writeLog(string.Format("服务列表已存在{0}服务", t.Name));
                                    continue;
                                }
                                object serv = Activator.CreateInstance(t);
                                tcpserver.Add(serv, t, t.Name);
                                services.Add(t.Name.ToLower());
                                writeLog(string.Format("{0}服务已添加到服务器列表", t.Name));
                            }
                        }
                    }
                }
                tcpserver.AddFilter(new HproseTokenFilter(allowSecretKeys));
                tcpserver.OnSendError   += tcpserver_OnSendError;
                tcpserver.IsDebugEnabled = true;
                tcpserver.Start();
                writeLog("服务已启动");
            }
            catch (Exception ex)
            {
                writeLog(string.Format("服务启动异常,信息:{0}", ex.Message));
            }
        }