| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- /*******************************************************************************
- * 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
- {
- /// <summary>
- /// 渠道工厂集合
- /// </summary>
- internal static class ChannelFactories
- {
- private static Dictionary<string, ChannelFactory> _channelFactories = new Dictionary<string, ChannelFactory>();
- /// <summary>
- /// 取得渠道工厂
- /// </summary>
- /// <typeparam name="TChannel">渠道类型</typeparam>
- /// <param name="endpointConfigName">终点名</param>
- /// <returns>渠道工厂</returns>
- public static ChannelFactory<TChannel> GetFactory<TChannel>(string endpointConfigName)
- {
- if (_channelFactories.ContainsKey(endpointConfigName))
- {
- return _channelFactories[endpointConfigName] as ChannelFactory<TChannel>;
- }
- lock (_channelFactories)
- {
- if (_channelFactories.ContainsKey(endpointConfigName))
- {
- return _channelFactories[endpointConfigName] as ChannelFactory<TChannel>;
- }
- 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<TChannel> channelFactory = new ChannelFactory<TChannel>(endpointConfigName, remoteAddress);
- channelFactory.Open();
- _channelFactories[endpointConfigName] = channelFactory;
- return channelFactory;
- }
- }
- /// <summary>
- /// 清空渠道工厂集合
- /// </summary>
- 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();
- }
- }
- }
- }
- }
|