/// <summary> /// 使用HA方式初始化服务 /// </summary> /// <param name="serviceName">服务名</param> /// <param name="computerName">获取配置使用的计算机名</param> /// <param name="centerUrl">HACenter的Url</param> public static void InitServiceHa(string serviceName, string computerName, string centerUrl) { if (_current != null && _current.ServiceName != NULL) { return; } lock (_syncRoot) { _current = new ServiceSettingsConfigProxy(serviceName, computerName); RpcHttpClientChannel channel = new RpcHttpClientChannel(); RpcProxyFactory.RegisterClientChannel(channel); HAGetConfigArgs args = new HAGetConfigArgs(); args.ServiceName = serviceName; args.ComputerName = computerName; var proxy = RpcProxyFactory.GetProxy <IHACenterConfigService>(centerUrl); HAServiceSettings settings = proxy.Invoke <HAGetConfigArgs, HAServiceSettings>( "LoadServiceSettings", args); IICConfigurationManager.Loader = new HAConfigurationLoader(serviceName, computerName, centerUrl); _current.UpdateConfig(ServiceRunMode.HAService, settings); TracingManager.UpdateConfig(); } }
/// <summary> /// 初始化Web /// </summary> public static void InitWeb() { if (_current != null && _current.ServiceName != NULL) { return; } lock (_syncRoot) { string runMode = WebConfigurationManager.AppSettings["RunMode"]; string centerUrl = WebConfigurationManager.AppSettings["CenterUrl"]; string serviceName = WebConfigurationManager.AppSettings["ServiceName"]; string computerName = WebConfigurationManager.AppSettings["ComputerName"] ?? Environment.MachineName; if (runMode == "LocalWeb") { _current = new ServiceSettingsConfigProxy(serviceName); IICConfigurationManager.Loader = new LocalConfigurationLoader(); _current.UpdateConfig(ServiceRunMode.LocalWeb, null); RpcProxyFactory.RegisterClientChannel(new RpcPipeClientChannel()); TracingManager.UpdateConfig(); } else { _current = new ServiceSettingsConfigProxy(serviceName, computerName); RpcProxyFactory.RegisterClientChannel(new RpcHttpClientChannel()); RpcProxyFactory.RegisterClientChannel(new RpcPipeClientChannel()); HAConfigurationLoader loader = new HAConfigurationLoader(serviceName, computerName, centerUrl); HAServiceSettings settings = loader.LoadServiceSettings(); IICConfigurationManager.Loader = loader; _current.UpdateConfig(ServiceRunMode.HAWeb, settings); TracingManager.UpdateConfig(); } } }