Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.LifecycleClient/Program.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.LifecycleClient/Program.cs	(revision 5677)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.LifecycleClient/Program.cs	(revision 5708)
@@ -6,5 +6,5 @@
     private static void Main(string[] args) {
       using (var factory = ClientFactory.CreateChannelFactory<IHiveService>("wsHttpBinding_IHiveService", null, "hiveslave", "hiveslave")) {
-        IHiveService client = factory.Obj.CreateChannel();
+        IHiveService client = factory.CreateChannel();
         client.TriggerLifecycle(true);
       }
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/TransactionManager.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/TransactionManager.cs	(revision 5677)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/TransactionManager.cs	(revision 5708)
@@ -1,24 +1,33 @@
 ﻿using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+using System.Transactions;
 using HeuristicLab.Services.Hive.Common;
-using System.Transactions;
-using HeuristicLab.Common;
-using HeuristicLab.Clients.Common;
 
 namespace HeuristicLab.Services.Hive.DataAccess {
   public class TransactionManager {
-    public Disposable<TransactionScope> OpenTransaction() {
-      TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = ApplicationConstants.IsolationLevelScope });
-      var disposable = new Disposable<TransactionScope>(transaction);
-      disposable.OnDisposing += new EventHandler<EventArgs<object>>(disposable_OnDisposing);
-      return disposable;
+    public void UseTransaction(Action call) {
+      TransactionScope transaction = CreateTransaction();
+      try {
+        call();
+        transaction.Complete();
+      }
+      finally {
+        transaction.Dispose();
+      }
     }
 
-    void disposable_OnDisposing(object sender, EventArgs<object> e) {
-      TransactionScope scope = (TransactionScope)e.Value;
-      scope.Complete();
-      scope.Dispose();
+    public T UseTransaction<T>(Func<T> call) {
+      TransactionScope transaction = CreateTransaction();
+      try {
+        T result = call();
+        transaction.Complete();
+        return result;
+      }
+      finally {
+        transaction.Dispose();
+      }
+    }
+
+    private static TransactionScope CreateTransaction() {
+      return new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = ApplicationConstants.IsolationLevelScope });
     }
   }
Index: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/HiveService.cs
===================================================================
--- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/HiveService.cs	(revision 5677)
+++ branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.4/HiveService.cs	(revision 5708)
@@ -35,5 +35,5 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
     public Guid AddJob(Job job, JobData jobData, IEnumerable<Guid> resourceIds) {
-      using (trans.OpenTransaction()) {
+      return trans.UseTransaction(() => {
         job.Id = dao.AddJob(job);
         jobData.JobId = job.Id;
@@ -49,5 +49,5 @@
         dao.UpdateJobState(job.Id, JobState.Waiting, null, auth.UserId, null);
         return jobData.JobId;
-      }
+      });
     }
 
@@ -55,8 +55,8 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
     public Guid AddChildJob(Guid parentJobId, Job job, JobData jobData) {
-      using (trans.OpenTransaction()) {
+      return trans.UseTransaction(() => {
         job.ParentJobId = parentJobId;
         return AddJob(job, jobData, dao.GetAssignedResources(parentJobId).Select(x => x.Id));
-      }
+      });
     }
 
@@ -97,7 +97,7 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
     public void UpdateJob(Job job) {
-      using (trans.OpenTransaction()) {
+      trans.UseTransaction(() => {
         dao.UpdateJob(job);
-      }
+      });
     }
 
@@ -106,9 +106,9 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
     public void UpdateJobData(Job job, JobData jobData) {
-      using (trans.OpenTransaction()) {
+      trans.UseTransaction(() => {
         jobData.LastUpdate = DateTime.Now;
         dao.UpdateJob(job);
         dao.UpdateJobData(jobData);
-      }
+      });
     }
 
@@ -117,7 +117,7 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
     public void DeleteJob(Guid jobId) {
-      using (trans.OpenTransaction()) {
+      trans.UseTransaction(() => {
         dao.DeleteJob(jobId);
-      }
+      });
     }
 
@@ -126,5 +126,5 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
     public void DeleteChildJobs(Guid parentJobId) {
-      using (trans.OpenTransaction()) {
+      trans.UseTransaction(() => {
         var jobs = GetChildJobs(parentJobId, true, false);
         foreach (var job in jobs) {
@@ -132,5 +132,5 @@
           dao.DeleteJobData(job.Id);
         };
-      }
+      });
     }
 
@@ -139,7 +139,5 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
     public Job UpdateJobState(Guid jobId, JobState jobState, Guid? slaveId, Guid? userId, string exception) {
-      using (trans.OpenTransaction()) {
-        return dao.UpdateJobState(jobId, jobState, slaveId, userId, exception);
-      }
+      return trans.UseTransaction(() => dao.UpdateJobState(jobId, jobState, slaveId, userId, exception));
     }
     #endregion
@@ -150,7 +148,7 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
     public void StopJob(Guid jobId) {
-      using (trans.OpenTransaction()) {
+      trans.UseTransaction(() => {
         throw new NotImplementedException();
-      }
+      });
     }
 
@@ -159,7 +157,7 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
     public void PauseJob(Guid jobId) {
-      using (trans.OpenTransaction()) {
+      trans.UseTransaction(() => {
         throw new NotImplementedException();
-      }
+      });
     }
     #endregion
@@ -189,9 +187,9 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
     public Guid AddHiveExperiment(HiveExperiment hiveExperimentDto) {
-      using (trans.OpenTransaction()) {
+      return trans.UseTransaction(() => {
         hiveExperimentDto.OwnerUserId = auth.UserId;
         hiveExperimentDto.DateCreated = DateTime.Now;
         return dao.AddHiveExperiment(hiveExperimentDto);
-      }
+      });
     }
 
@@ -199,7 +197,7 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
     public void UpdateHiveExperiment(HiveExperiment hiveExperimentDto) {
-      using (trans.OpenTransaction()) {
+      trans.UseTransaction(() => {
         dao.UpdateHiveExperiment(hiveExperimentDto);
-      }
+      });
     }
 
@@ -207,8 +205,8 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
     public void DeleteHiveExperiment(Guid hiveExperimentId) {
-      using (trans.OpenTransaction()) {
+      trans.UseTransaction(() => {
         HiveExperiment he = dao.GetHiveExperiment(hiveExperimentId);
         dao.DeleteHiveExperiment(hiveExperimentId); // child jobs will be deleted by db-trigger
-      }
+      });
     }
     #endregion
@@ -217,5 +215,5 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
     public void Hello(Slave slaveInfo) {
-      using (trans.OpenTransaction()) {
+      trans.UseTransaction(() => {
         var slave = dao.GetSlave(slaveInfo.Id);
 
@@ -225,10 +223,10 @@
           dao.UpdateSlave(slaveInfo);
         }
-      }
+      });
     }
 
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Slave)]
     public void GoodBye(Guid slaveId) {
-      using (trans.OpenTransaction()) {
+      trans.UseTransaction(() => {
         var slave = dao.GetSlave(slaveId);
         if (slave != null) {
@@ -236,5 +234,5 @@
           dao.UpdateSlave(slave);
         }
-      }
+      });
     }
     #endregion
@@ -244,8 +242,5 @@
     public List<MessageContainer> Heartbeat(Heartbeat heartbeat) {
       TriggerLifecycle(false);
-
-      using (trans.OpenTransaction()) {
-        return heartbeatManager.ProcessHeartbeat(heartbeat);
-      }
+      return trans.UseTransaction(() => heartbeatManager.ProcessHeartbeat(heartbeat));
     }
     #endregion
@@ -255,5 +250,5 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
     public Guid AddPlugin(Plugin plugin, List<PluginData> pluginDatas) {
-      using (trans.OpenTransaction()) {
+      return trans.UseTransaction(() => {
         plugin.UserId = auth.UserId;
         plugin.DateCreated = DateTime.Now;
@@ -264,5 +259,5 @@
         }
         return pluginId;
-      }
+      });
     }
 
@@ -280,5 +275,5 @@
       List<PluginData> pluginDatas = new List<PluginData>();
 
-      using (trans.OpenTransaction()) {
+      return trans.UseTransaction(() => {
         foreach (Guid guid in pluginIds) {
           List<PluginData> pluginData = dao.GetPluginDatas(x => x.PluginId == guid).ToList();
@@ -290,5 +285,5 @@
         }
         return pluginDatas;
-      }
+      });
     }
 
@@ -299,7 +294,5 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
     public Guid AddSlave(Slave slave) {
-      using (trans.OpenTransaction()) {
-        return dao.AddSlave(slave);
-      }
+      return trans.UseTransaction(() => dao.AddSlave(slave));
     }
 
@@ -307,7 +300,5 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
     public Guid AddSlaveGroup(SlaveGroup slaveGroup) {
-      using (trans.OpenTransaction()) {
-        return dao.AddSlaveGroup(slaveGroup);
-      }
+      return trans.UseTransaction(() => dao.AddSlaveGroup(slaveGroup));
     }
 
@@ -337,7 +328,7 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
     public void UpdateSlave(Slave slave) {
-      using (trans.OpenTransaction()) {
+      trans.UseTransaction(() => {
         dao.UpdateSlave(slave);
-      }
+      });
     }
 
@@ -345,7 +336,7 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
     public void UpdateSlaveGroup(SlaveGroup slaveGroup) {
-      using (trans.OpenTransaction()) {
+      trans.UseTransaction(() => {
         dao.UpdateSlaveGroup(slaveGroup);
-      }
+      });
     }
 
@@ -353,7 +344,7 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
     public void DeleteSlave(Guid slaveId) {
-      using (trans.OpenTransaction()) {
+      trans.UseTransaction(() => {
         dao.DeleteSlave(slaveId);
-      }
+      });
     }
 
@@ -361,7 +352,7 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
     public void DeleteSlaveGroup(Guid slaveGroupId) {
-      using (trans.OpenTransaction()) {
+      trans.UseTransaction(() => {
         dao.DeleteSlaveGroup(slaveGroupId);
-      }
+      });
     }
 
@@ -369,9 +360,9 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
     public void AddResourceToGroup(Guid slaveGroupId, Guid resourceId) {
-      using (trans.OpenTransaction()) {
+      trans.UseTransaction(() => {
         var resource = dao.GetResource(resourceId);
         resource.ParentResourceId = slaveGroupId;
         dao.UpdateResource(resource);
-      }
+      });
     }
 
@@ -379,9 +370,9 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
     public void RemoveResourceFromGroup(Guid slaveGroupId, Guid resourceId) {
-      using (trans.OpenTransaction()) {
+      trans.UseTransaction(() => {
         var resource = dao.GetResource(resourceId);
         resource.ParentResourceId = null;
         dao.UpdateResource(resource);
-      }
+      });
     }
 
@@ -389,5 +380,5 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Client)]
     public Guid GetResourceId(string resourceName) {
-      using (trans.OpenTransaction()) {
+      return trans.UseTransaction(() => {
         var resource = dao.GetResources(x => x.Name == resourceName).FirstOrDefault();
         if (resource != null) {
@@ -396,9 +387,9 @@
           return Guid.Empty;
         }
-      }
+      });
     }
 
     public void TriggerLifecycle(bool force) {
-      using (trans.OpenTransaction()) {
+      trans.UseTransaction(() => {
         DateTime lastCleanup = dao.GetLastCleanup();
         if (force || DateTime.Now - lastCleanup > TimeSpan.FromSeconds(59)) {
@@ -406,5 +397,5 @@
           lifecycleManager.Cleanup();
         }
-      }
+      });
     }
     #endregion
@@ -433,28 +424,24 @@
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
     public Guid AddAppointment(Appointment appointment) {
-      using (trans.OpenTransaction()) {
-        return dao.AddAppointment(appointment);
-      }
+      return trans.UseTransaction(() => dao.AddAppointment(appointment));
     }
 
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
     public void DeleteAppointment(Guid appointmentId) {
-      using (trans.OpenTransaction()) {
+      trans.UseTransaction(() => {
         dao.DeleteAppointment(appointmentId);
-      }
+      });
     }
 
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
     public void UpdateAppointment(Appointment appointment) {
-      using (trans.OpenTransaction()) {
+      trans.UseTransaction(() => {
         dao.UpdateAppointment(appointment);
-      }
+      });
     }
 
     // [PrincipalPermission(SecurityAction.Demand, Role = HiveRoles.Administrator)]
     public IEnumerable<Appointment> GetScheduleForResource(Guid resourceId) {
-      using (trans.OpenTransaction()) {
-        return dao.GetAppointments(x => x.ResourceId == resourceId);
-      }
+      return trans.UseTransaction(() => dao.GetAppointments(x => x.ResourceId == resourceId));
     }
     #endregion
