private static T CreateChannel <T>() where T : class { string key = typeof(T).FullName; ServiceEndpointEntity fromCache = CacheHelper.GetFromCache <ServiceEndpointEntity>(key); if (fromCache == null) { Configuration configuration = null; configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ServiceModelSectionGroup smsg = (ServiceModelSectionGroup)configuration.GetSectionGroup("system.serviceModel"); fromCache = GetEndpointEntity <T>(smsg); if (fromCache == null) { throw new Exception("Invalid type" + typeof(T)); } SetBindingParam(fromCache.ChannelBinding, smsg); } CacheHelper.AddToCache(key, fromCache); return(CreateChanel <T>(fromCache)); }
private static T CreateChanel <T>(ServiceEndpointEntity entity) { ChannelFactory <T> factory = new ChannelFactory <T>(entity.ChannelBinding, entity.ChannelAddress); return(factory.CreateChannel()); }
private static ServiceEndpointEntity GetEndpointEntity <T>(ServiceModelSectionGroup smsg) where T : class { foreach (ChannelEndpointElement ce in smsg.Client.Endpoints) { if (ce.Contract == typeof(T).FullName) { var entity = new ServiceEndpointEntity() { ChannelBinding = new BasicHttpBinding(), ChannelAddress = new EndpointAddress(ce.Address) }; return(entity); } } return(null); }