コード例 #1
0
        public static ReferenceCountedChannel <TChannel> GetChannel(Proxy <TChannel> proxy)
        {
            ReferenceCountedChannel <TChannel> channel;
            EndpointAddress            to           = proxy.To;
            ChannelMruCacheKey         key          = new ChannelMruCacheKey(to.Uri.AbsoluteUri, to.Identity);
            ChannelMruCache <TChannel> channelCache = proxy.ChannelCache;

            lock (channelCache)
            {
                if (channelCache.TryGetValue(key, out channel))
                {
                    channel.AddRef();
                    return(channel);
                }
            }
            TChannel local = proxy.CreateChannel(new EndpointAddress(to.Uri, to.Identity, new AddressHeader[0]));

            lock (channelCache)
            {
                if (!channelCache.TryGetValue(key, out channel))
                {
                    channel = new ReferenceCountedChannel <TChannel>(proxy, local, key);
                    channelCache.Add(key, channel);
                }
                else
                {
                    ((IChannel)local).Close();
                }
                channel.AddRef();
            }
            return(channel);
        }
コード例 #2
0
 private ReferenceCountedChannel(Proxy <TChannel> proxy, TChannel channel, ChannelMruCacheKey key)
 {
     this.proxy   = proxy;
     this.channel = channel;
     this.key     = key;
 }