/// <summary> /// 从注册表容器中根据Message的Action找到匹配的 binding和 endpointaddress /// </summary> /// <param name="requestMessage"></param> /// <param name="binding"></param> /// <param name="endpointAddress"></param> private void GetServiceEndpoint(Message requestMessage, out EndpointAddress endpointAddress) { string ns = "http://www.efwplus.cn/"; string routerID = GetHeaderValue("routerID", ns); string cmd = GetHeaderValue("CMD", ns); string contractNamespace = requestMessage.Headers.Action.Substring(0, requestMessage.Headers.Action.LastIndexOf("/")); RegistrationInfo regInfo = null; if (RouterHandlerService.RoundRobinCount.ContainsKey(routerID)) { int key = RouterHandlerService.RoundRobinCount[routerID]; regInfo = RouterHandlerService.RegistrationList[key]; if (cmd == "Quit") { regInfo.ClientNum -= 1; } } else { //根据指定的协议名称空间从注册表容器中得到注册项列表 var results = from item in RouterHandlerService.RegistrationList where item.Value.ContractNamespace.Contains(contractNamespace) orderby item.Value.ClientNum ascending select item; if (results.Count <KeyValuePair <int, RegistrationInfo> >() > 0) { var val = results.First <KeyValuePair <int, RegistrationInfo> >(); RouterHandlerService.RoundRobinCount.Add(routerID, val.Key); val.Value.ClientNum += 1; regInfo = val.Value; } } Uri addressUri = new Uri(regInfo.Address); //binding = CustomBindConfig.GetRouterBinding(addressUri.Scheme); endpointAddress = new EndpointAddress(regInfo.Address); //重设Message的目标终结点 requestMessage.Headers.To = new Uri(regInfo.Address); hostwcfRouter(RegistrationList.Values.ToList()); }
/// <summary> /// 加载路由器的路由表 /// </summary> public static void AddRouterBill() { string _address = null; string _contractname = null; string _contractnamespace = null; XElement xes = XElement.Load(System.Windows.Forms.Application.StartupPath + "\\Config\\RouterBill.xml"); IEnumerable <XElement> elements = from e in xes.Elements("record") select e; foreach (XElement xe in elements) { _address = xe.Element("address").Value; _contractname = xe.Element("ContractName").Value; _contractnamespace = xe.Element("ContractNamespace").Value; RegistrationInfo registrationInfo = new RegistrationInfo { Address = _address, ContractName = _contractname, ContractNamespace = _contractnamespace }; if (!RouterHandlerService.RegistrationList.ContainsKey(registrationInfo.GetHashCode())) { RouterHandlerService.RegistrationList.Add(registrationInfo.GetHashCode(), registrationInfo); } } }
/// <summary> /// 加载路由器的路由表 /// </summary> public static void AddRouterBill() { string _address = null; string _contractname = null; string _contractnamespace = null; XElement xes = XElement.Load(System.Windows.Forms.Application.StartupPath + "\\Config\\RouterBill.xml"); IEnumerable<XElement> elements = from e in xes.Elements("record") select e; foreach (XElement xe in elements) { _address = xe.Element("address").Value; _contractname = xe.Element("ContractName").Value; _contractnamespace = xe.Element("ContractNamespace").Value; RegistrationInfo registrationInfo = new RegistrationInfo { Address = _address, ContractName = _contractname, ContractNamespace = _contractnamespace }; if (!RouterHandlerService.RegistrationList.ContainsKey(registrationInfo.GetHashCode())) { RouterHandlerService.RegistrationList.Add(registrationInfo.GetHashCode(), registrationInfo); } } }