示例#1
0
        //string ns = "http://www.efwplus.cn/";
        public string CreateClient(string clientName)
        {
            //客户端回调
            IDataReply      mCallBack = OperationContext.Current.GetCallbackChannel <IDataReply>();
            HeaderParameter para      = HeaderOperater.GetHeaderValue(OperationContext.Current.RequestContext.RequestMessage);
            string          ClientID  = ClientManage.CreateClient(clientName, DateTime.Now, mCallBack, para.pluginname, para.replyidentify);

            return(ClientID);
        }
示例#2
0
        /// <summary>
        /// 截获从Client端发送的消息转发到目标终结点并获得返回值给Client端
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public Message ProcessMessage(Message requestMessage)
        {
            try
            {
                begintime();
                IRouterService  proxy = null;
                HeaderParameter para  = HeaderOperater.GetHeaderValue(requestMessage);

                if (RouterServerManage.routerDic.ContainsKey(para.routerid))
                {
                    proxy = RouterServerManage.routerDic[para.routerid];
                    para.replyidentify = RouterServerManage.headParaDic[para.routerid].replyidentify;
                }
                else
                {
                    //Binding binding = null;
                    EndpointAddress endpointAddress = null;
                    Uri             touri           = null;
                    para = RouterServerManage.AddClient(requestMessage, para, out endpointAddress, out touri);
                    requestMessage.Headers.To = touri;

                    IDuplexRouterCallback callback = OperationContext.Current.GetCallbackChannel <IDuplexRouterCallback>();
                    NetTcpBinding         tbinding = new NetTcpBinding("NetTcpBinding_WCFHandlerService");
                    DuplexChannelFactory <IRouterService> factory = new DuplexChannelFactory <IRouterService>(new InstanceContext(new DuplexRouterCallback(callback)), tbinding, endpointAddress);
                    proxy = factory.CreateChannel();

                    //缓存会话
                    RouterServerManage.routerDic.Add(para.routerid, proxy);
                    RouterServerManage.headParaDic.Add(para.routerid, para);
                }

                Message responseMessage = null;
                HeaderOperater.AddMessageHeader(requestMessage, para);//增加自定义消息头
                responseMessage = proxy.ProcessMessage(requestMessage);

                if (para.cmd == "Quit")
                {
                    //关闭连接释放缓存会话
                    RouterServerManage.RemoveClient(para);
                }

                double outtime = endtime();
                // 请求消息记录
                if (WcfServerManage.IsDebug)
                {
                    RouterServerManage.hostwcfMsg(Color.Black, DateTime.Now, String.Format("路由请求消息发送(耗时[" + outtime + "]):  {0}", requestMessage.Headers.Action));
                }


                return(responseMessage);
            }
            catch (Exception e)
            {
                return(Message.CreateMessage(requestMessage.Version, FaultCode.CreateReceiverFaultCode("error", RouterServerManage.ns), e.Message, requestMessage.Headers.Action));
            }
        }
        //异步请求
        public IAsyncResult BeginProcessRequest(string clientId, string controller, string method, string jsondata, AsyncCallback callback, object asyncState)
        {
            string pluginname = null;
            string cname      = null;

            string[] names = controller.Split(new char[] { '@' });
            if (names.Length == 2)
            {
                pluginname = names[0];
                cname      = names[1];
            }
            HeaderParameter para = HeaderOperater.GetHeaderValue(OperationContext.Current.RequestContext.RequestMessage);

            return(new CompletedAsyncResult <string>(WcfServerManage.ProcessRequest(clientId, pluginname, cname, method, jsondata, para)));
        }
        //服务请求
        public string ProcessRequest(string clientId, string controller, string method, string jsondata)
        {
            string pluginname = null;
            string cname      = null;

            string[] names = controller.Split(new char[] { '@' });
            if (names.Length == 2)
            {
                pluginname = names[0];
                cname      = names[1];
            }
            HeaderParameter para = HeaderOperater.GetHeaderValue(OperationContext.Current.RequestContext.RequestMessage);

            return(WcfServerManage.ProcessRequest(clientId, pluginname, cname, method, jsondata, para));
        }
        public string CreateDomain(string ipAddress)
        {
            //客户端回调
            IClientService  mCallBack = OperationContext.Current.GetCallbackChannel <IClientService>();
            HeaderParameter para      = HeaderOperater.GetHeaderValue(OperationContext.Current.RequestContext.RequestMessage);
            string          ClientID  = WcfServerManage.CreateClient(OperationContext.Current.SessionId, ipAddress, DateTime.Now, mCallBack, para.pluginname, para.replyidentify);

            //异步执行同步缓存
            new Action(delegate()
            {
                if (para.pluginname == "SuperPlugin")
                {
                    //创建连接时候会将上级中间件的缓存同步到下级中间件
                    DistributedCacheManage.SyncAllCache(mCallBack);
                }
            }).BeginInvoke(null, null);

            return(ClientID);
        }
示例#6
0
        public string ProcessRequest(string clientId, string plugin, string controller, string method, string jsondata)
        {
            HeaderParameter para = HeaderOperater.GetHeaderValue(OperationContext.Current.RequestContext.RequestMessage);

            return(DataManage.ProcessRequest(clientId, plugin, controller, method, jsondata, para));
        }
示例#7
0
        public IAsyncResult BeginProcessRequest(string clientId, string plugin, string controller, string method, string jsondata, AsyncCallback callback, object asyncState)
        {
            HeaderParameter para = HeaderOperater.GetHeaderValue(OperationContext.Current.RequestContext.RequestMessage);

            return(new CompletedAsyncResult <string>(DataManage.ProcessRequest(clientId, plugin, controller, method, jsondata, para)));
        }
        public Message ProcessMessage(Message requestMessage)
        {
            try
            {
                //计时器
                Stopwatch sw = new Stopwatch();
                sw.Start();

                IRouterBaseHandler proxy = null;
                HeaderParameter    para  = HeaderOperater.GetHeaderValue(requestMessage);

                if (RouterManage.routerDic.ContainsKey(para.routerid))
                {
                    proxy = RouterManage.routerDic[para.routerid];
                    para.replyidentify = RouterManage.headParaDic[para.routerid].replyidentify;
                }
                else
                {
                    //Binding binding = null;
                    EndpointAddress endpointAddress = null;
                    Uri             touri           = null;
                    para = RouterManage.AddClient(requestMessage, para, out endpointAddress, out touri);
                    requestMessage.Headers.To = touri;

                    IRouterBaseReply callback = OperationContext.Current.GetCallbackChannel <IRouterBaseReply>();
                    NetTcpBinding    tbinding = new NetTcpBinding("NetTcpBinding_BaseService");
                    DuplexChannelFactory <IRouterBaseHandler> factory = new DuplexChannelFactory <IRouterBaseHandler>(new InstanceContext(new ReplyRouterBaseCallback(callback)), tbinding, endpointAddress);
                    proxy = factory.CreateChannel();

                    //缓存会话
                    RouterManage.routerDic.Add(para.routerid, proxy);
                    RouterManage.headParaDic.Add(para.routerid, para);
                }

                Message responseMessage = null;
                try
                {
                    HeaderOperater.AddMessageHeader(requestMessage, para);//增加自定义消息头
                    responseMessage = proxy.ProcessMessage(requestMessage);
                }
                catch (CommunicationException e)
                {
                    RouterManage.RemoveClient(para);
                    throw e;
                }
                if (para.cmd == "Quit")
                {
                    //关闭连接释放缓存会话
                    RouterManage.RemoveClient(para);
                }

                //double outtime = endtime();
                // 请求消息记录
                if (WcfGlobal.IsDebug)
                {
                    MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Black, String.Format("路由请求消息发送(耗时[" + sw.Elapsed.TotalMilliseconds + "]):  {0}", requestMessage.Headers.Action));
                }


                return(responseMessage);
            }
            catch (Exception e)
            {
                return(Message.CreateMessage(requestMessage.Version, FaultCode.CreateReceiverFaultCode("error", RouterManage.ns), e.Message, requestMessage.Headers.Action));
            }
        }