Changeset 5526 for branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceLocator.cs
- Timestamp:
- 02/21/11 17:35:42 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.4/ServiceLocator.cs
r5405 r5526 20 20 #endregion 21 21 22 using System; 23 using System.ServiceModel; 22 24 using HeuristicLab.Clients.Common; 23 25 using HeuristicLab.Services.Hive.Common.ServiceContracts; … … 38 40 } 39 41 40 public Disposable<IHiveService> GetService() { 41 return ClientFactory.CreateClient<IHiveService>("wsHttpBinding_IHiveService"); 42 private string username; 43 public string Username { 44 get { return username; } 45 set { username = value; } 42 46 } 43 47 44 public Disposable<IHiveService> GetService(string username, string password) { 45 return ClientFactory.CreateClient<IHiveService>("wsHttpBinding_IHiveService", null, username, password); 48 private string password; 49 public string Password { 50 get { return password; } 51 set { password = value; } 52 } 53 54 public Disposable<ChannelFactory<IHiveService>> GetService() { 55 if (string.IsNullOrEmpty(username) && string.IsNullOrEmpty(password)) { 56 return ClientFactory.CreateChannelFactory<IHiveService>("wsHttpBinding_IHiveService"); 57 } else { 58 return ClientFactory.CreateChannelFactory<IHiveService>("wsHttpBinding_IHiveService", null, username, password); 59 } 60 } 61 62 public void CallHiveService(Action<IHiveService> call) { 63 using (var channelFactory = this.GetService()) { 64 var service = channelFactory.Obj.CreateChannel(); 65 call(service); 66 } // disposing the channelfactory is done by the disposable object; the channel gets disposed when the channelfactory is disposed 67 } 68 69 private T CallHiveService<T>(Func<IHiveService, T> call) { 70 using (var channelFactory = this.GetService()) { 71 var service = channelFactory.Obj.CreateChannel(); 72 return call(service); 73 } // disposing the channelfactory is done by the disposable object; the channel gets disposed when the channelfactory is disposed 74 } 75 76 T IServiceLocator.CallHiveService<T>(Func<IHiveService, T> call) { 77 return CallHiveService<T>(call); 46 78 } 47 79 }
Note: See TracChangeset
for help on using the changeset viewer.