- Timestamp:
- 03/16/11 00:23:01 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Clients.Common/3.3/ClientFactory.cs
r5527 r5701 28 28 namespace HeuristicLab.Clients.Common { 29 29 public static class ClientFactory { 30 #region CreateClient Methods 30 31 public static T CreateClient<T, I>() 31 32 where T : ClientBase<I>, I … … 62 63 return client; 63 64 } 65 #endregion 64 66 65 public static Disposable<ChannelFactory<I>> CreateChannelFactory<I>(string endpointConfigurationName) where I : class { 67 #region CreateChannelFactory Methods 68 public static Disposable<ChannelFactory<I>> CreateChannelFactory<I>(string endpointConfigurationName) 69 where I : class { 66 70 return CreateChannelFactory<I>(endpointConfigurationName, null); 67 71 } 68 public static Disposable<ChannelFactory<I>> CreateChannelFactory<I>(string endpointConfigurationName, string remoteAddress) where I : class { 72 public static Disposable<ChannelFactory<I>> CreateChannelFactory<I>(string endpointConfigurationName, string remoteAddress) 73 where I : class { 69 74 return CreateChannelFactory<I>(endpointConfigurationName, remoteAddress, Settings.Default.UserName, Settings.Default.Password); 70 75 } 71 public static Disposable<ChannelFactory<I>> CreateChannelFactory<I>(string endpointConfigurationName, string remoteAddress, string userName, string password) where I : class { 72 ChannelFactory<I> factory = GetChannelFactory<I>(endpointConfigurationName, userName, password); 73 74 if (!string.IsNullOrEmpty(remoteAddress)) { 75 SetEndpointAddress(factory.Endpoint, remoteAddress); 76 } 77 var disposable = new Disposable<ChannelFactory<I>>(factory); 78 disposable.OnDisposing += new EventHandler<EventArgs<object>>(disposable_OnDisposing); 79 return disposable; 80 } 81 82 private static void disposable_OnDisposing(object sender, EventArgs<object> e) { 83 DisposeCommunicationObject((ICommunicationObject)e.Value); 84 ((Disposable)sender).OnDisposing -= new EventHandler<EventArgs<object>>(disposable_OnDisposing); 85 } 86 87 private static ChannelFactory<I> GetChannelFactory<I>(string endpointConfigurationName, string userName, string password) where I : class { 88 var channelFactory = new ChannelFactory<I>(endpointConfigurationName); 76 public static Disposable<ChannelFactory<I>> CreateChannelFactory<I>(string endpointConfigurationName, string remoteAddress, string userName, string password) 77 where I : class { 78 ChannelFactory<I> channelFactory = new ChannelFactory<I>(endpointConfigurationName); 89 79 channelFactory.Credentials.UserName.UserName = userName; 90 80 channelFactory.Credentials.UserName.Password = password; 91 81 channelFactory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None; 92 return channelFactory; 82 83 if (!string.IsNullOrEmpty(remoteAddress)) { 84 SetEndpointAddress(channelFactory.Endpoint, remoteAddress); 85 } 86 87 Disposable<ChannelFactory<I>> disposableChannelFactory = new Disposable<ChannelFactory<I>>(channelFactory); 88 disposableChannelFactory.OnDisposing += new EventHandler<EventArgs<object>>(DisposableChannelFactory_OnDisposing); 89 return disposableChannelFactory; 93 90 } 91 92 private static void DisposableChannelFactory_OnDisposing(object sender, EventArgs<object> e) { 93 DisposeCommunicationObject((ICommunicationObject)e.Value); 94 ((Disposable)sender).OnDisposing -= new EventHandler<EventArgs<object>>(DisposableChannelFactory_OnDisposing); 95 } 96 #endregion 94 97 95 98 public static void DisposeCommunicationObject(ICommunicationObject obj) { … … 104 107 } 105 108 106 /// <summary> 107 /// This method changes the endpoint-address while preserving the identity-certificate defined in the config file 108 /// </summary> 109 #region Helpers 109 110 private static void SetEndpointAddress(ServiceEndpoint endpoint, string remoteAddress) { 110 EndpointAddressBuilder endpointAddressbuilder = new EndpointAddressBuilder(endpoint.Address); 111 UriBuilder uriBuilder = new UriBuilder(endpointAddressbuilder.Uri); 111 // change the endpoint address and preserve the identity certificate defined in the config file 112 EndpointAddressBuilder endpointAddressBuilder = new EndpointAddressBuilder(endpoint.Address); 113 UriBuilder uriBuilder = new UriBuilder(endpointAddressBuilder.Uri); 112 114 uriBuilder.Host = remoteAddress; 113 endpointAddress builder.Uri = uriBuilder.Uri;114 endpoint.Address = endpointAddress builder.ToEndpointAddress();115 endpointAddressBuilder.Uri = uriBuilder.Uri; 116 endpoint.Address = endpointAddressBuilder.ToEndpointAddress(); 115 117 } 118 #endregion 116 119 } 117 120 }
Note: See TracChangeset
for help on using the changeset viewer.