Esempio n. 1
0
        private void Init()
        {
            CallbackService = new CalculatorCallbackService();
            //CallbackService.Quit += new EventHandler(cb_Quit);
            CallbackService.Processed += cb_Process;

            InstanceContext callback = new InstanceContext(CallbackService);

            ChannelFactory = new DuplexChannelFactory <ICalculator>(callback, "calculatorservice");

            Calculator = ChannelFactory.CreateChannel();
            SessionUtility.Callback = CallbackService as ISessionCallback;
            SessionUtility.Channel  = Calculator as ISessionManagement;
            //calculator.Add(1, 2);
            //请求服务器端数据
            SessionClientInfo clientInfo = new SessionClientInfo()
            {
                IPAddress = "127.0.0.1", HostName = "1", UserName = "******"
            };

            TimeSpan timeout;

            Calculator.StartSession(clientInfo, out timeout);

            //var client = new CalculatorClient(callback);
            //var d1 = client.GetProcessData("aa");
            var data = Calculator.GetProcessData("client1");

            if (data != null && data.Count > 0)
            {
                //Thread t1 = new Thread(new ParameterizedThreadStart(DoSomethingWithParameterV2));
                //t1.SetApartmentState(ApartmentState.STA);
                //t1.Start(data);
            }
        }
Esempio n. 2
0
        private void Init()
        {
            CallbackService = new CalculatorCallbackService();
            //CallbackService.Quit += new EventHandler(cb_Quit);
            CallbackService.Processed += cb_Process;

            InstanceContext callback = new InstanceContext(CallbackService);
            ChannelFactory = new DuplexChannelFactory<ICalculator>(callback, "calculatorservice");

            Calculator = ChannelFactory.CreateChannel();
            SessionUtility.Callback = CallbackService as ISessionCallback;
            SessionUtility.Channel = Calculator as ISessionManagement;
            //calculator.Add(1, 2);
            //请求服务器端数据
            SessionClientInfo clientInfo = new SessionClientInfo() { IPAddress = "127.0.0.1", HostName = "1", UserName = "******" };

            TimeSpan timeout;
            Calculator.StartSession(clientInfo, out timeout);

            //var client = new CalculatorClient(callback);
            //var d1 = client.GetProcessData("aa");
            var data = Calculator.GetProcessData("client1");
            if (data != null && data.Count > 0)
            {
                //Thread t1 = new Thread(new ParameterizedThreadStart(DoSomethingWithParameterV2));
                //t1.SetApartmentState(ApartmentState.STA);
                //t1.Start(data);
            }
        }