예제 #1
0
 /// <summary>
 /// 初始化池
 /// </summary>
 /// <param name="binding">Binding方式</param>
 /// <param name="address">服务地址</param>
 public WcfTcpClientPool(Binding binding, int connections, string[] address)
 {
     foreach (string item in address)
     {
         WcfTcpClientNode <T> node = new WcfTcpClientNode <T>(binding, item);
         node.Initialize(connections);
         mNodes.Add(node);
     }
 }
예제 #2
0
        /// <summary>
        /// 从池中获取一个连接
        /// </summary>
        /// <returns>object</returns>
        public object GetClient()
        {
            int count = 0;

            while (count <= mNodes.Count)
            {
                Index.Value++;
                if (Index.Value >= mNodes.Count)
                {
                    Index.Value = 0;
                }
                WcfTcpClientNode <T> node = mNodes[Index.Value];
                if (node.Status == NodeStatus.None)
                {
                    return((WcfTcpClient <T>)node.Pop());
                }
                else
                {
                    node.Verify();
                }
                count++;
            }
            return(null);
        }