Changeset 5527 for trunk/sources
- Timestamp:
- 02/21/11 17:37:20 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Clients.Common/3.3/ClientFactory.cs
r5445 r5527 22 22 using System; 23 23 using System.ServiceModel; 24 using System.ServiceModel.Description; 24 25 using HeuristicLab.Clients.Common.Properties; 25 using System.ServiceModel.Description;26 using System.Collections;27 using System.Collections.Generic;28 26 using HeuristicLab.Common; 29 27 … … 65 63 } 66 64 67 public static Disposable< I> CreateClient<I>(string endpointConfigurationName) where I : class {68 return CreateC lient<I>(endpointConfigurationName, null);65 public static Disposable<ChannelFactory<I>> CreateChannelFactory<I>(string endpointConfigurationName) where I : class { 66 return CreateChannelFactory<I>(endpointConfigurationName, null); 69 67 } 70 public static Disposable< I> CreateClient<I>(string endpointConfigurationName, string remoteAddress) where I : class {71 return CreateC lient<I>(endpointConfigurationName, remoteAddress, Settings.Default.UserName, Settings.Default.Password);68 public static Disposable<ChannelFactory<I>> CreateChannelFactory<I>(string endpointConfigurationName, string remoteAddress) where I : class { 69 return CreateChannelFactory<I>(endpointConfigurationName, remoteAddress, Settings.Default.UserName, Settings.Default.Password); 72 70 } 73 public static Disposable< I> CreateClient<I>(string endpointConfigurationName, string remoteAddress, string userName, string password) where I : class {71 public static Disposable<ChannelFactory<I>> CreateChannelFactory<I>(string endpointConfigurationName, string remoteAddress, string userName, string password) where I : class { 74 72 ChannelFactory<I> factory = GetChannelFactory<I>(endpointConfigurationName, userName, password); 75 73 … … 77 75 SetEndpointAddress(factory.Endpoint, remoteAddress); 78 76 } 79 Disposable<I> disposable = new Disposable<I>(factory.CreateChannel());77 var disposable = new Disposable<ChannelFactory<I>>(factory); 80 78 disposable.OnDisposing += new EventHandler<EventArgs<object>>(disposable_OnDisposing); 81 82 79 return disposable; 83 80 } … … 88 85 } 89 86 90 private static IDictionary<ChannelProperties, ChannelFactory> channelFactoryCache = new Dictionary<ChannelProperties, ChannelFactory>();91 87 private static ChannelFactory<I> GetChannelFactory<I>(string endpointConfigurationName, string userName, string password) where I : class { 92 ChannelProperties key = new ChannelProperties(typeof(I), endpointConfigurationName, userName, password); 93 if (!channelFactoryCache.ContainsKey(key)) { 94 channelFactoryCache.Add(key, new ChannelFactory<I>(endpointConfigurationName)); 95 channelFactoryCache[key].Credentials.UserName.UserName = userName; 96 channelFactoryCache[key].Credentials.UserName.Password = password; 97 channelFactoryCache[key].Credentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; 98 } 99 return (ChannelFactory<I>)channelFactoryCache[key]; 88 var channelFactory = new ChannelFactory<I>(endpointConfigurationName); 89 channelFactory.Credentials.UserName.UserName = userName; 90 channelFactory.Credentials.UserName.Password = password; 91 channelFactory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; 92 return channelFactory; 100 93 } 101 94 … … 122 115 } 123 116 } 124 125 internal struct ChannelProperties {126 public Type type;127 public string endpointConfigurationName;128 public string userName;129 public string password;130 131 public ChannelProperties(Type type, string endpointConfigurationName, string userName, string password) {132 this.type = type;133 this.endpointConfigurationName = endpointConfigurationName;134 this.userName = userName;135 this.password = password;136 }137 }138 117 }
Note: See TracChangeset
for help on using the changeset viewer.