예제 #1
0
        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));
        }
예제 #2
0
        private static T CreateChanel <T>(ServiceEndpointEntity entity)
        {
            ChannelFactory <T> factory
                = new ChannelFactory <T>(entity.ChannelBinding, entity.ChannelAddress);

            return(factory.CreateChannel());
        }
예제 #3
0
 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);
 }