/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:ChannelFactories.cs * 2.功能描述:渠道工厂集合 * 编辑履历: * 作者 日期 版本 修改内容 * 陈晓野 2014/08/13 1.00 新建 *******************************************************************************/ using System.Collections.Generic; using System.ServiceModel; namespace Dongke.IBOSS.PRD.WCF.Proxys.ServiceProxy { /// /// 渠道工厂集合 /// internal static class ChannelFactories { private static Dictionary _channelFactories = new Dictionary(); /// /// 取得渠道工厂 /// /// 渠道类型 /// 终点名 /// 渠道工厂 public static ChannelFactory GetFactory(string endpointConfigName) { if (_channelFactories.ContainsKey(endpointConfigName)) { return _channelFactories[endpointConfigName] as ChannelFactory; } lock (_channelFactories) { if (_channelFactories.ContainsKey(endpointConfigName)) { return _channelFactories[endpointConfigName] as ChannelFactory; } string ur = "http://{0}:{1}/{2}/{3}"; string uri = string.Format(ur, ProxySettings.IP, ProxySettings.Port, ProxySettings.ServiceName, endpointConfigName); EndpointAddress remoteAddress = new EndpointAddress(uri); ChannelFactory channelFactory = new ChannelFactory(endpointConfigName, remoteAddress); channelFactory.Open(); _channelFactories[endpointConfigName] = channelFactory; return channelFactory; } } /// /// 清空渠道工厂集合 /// public static void Clear() { if (_channelFactories.Count > 0) { lock (_channelFactories) { foreach (ChannelFactory item in _channelFactories.Values) { try { item.Close(); } //catch (System.Exception ex) catch { item.Abort(); } } _channelFactories.Clear(); } } } } }