using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using HeuristicLab.Services.Optimization.ControllerService.General; using HeuristicLab.Services.Optimization.ControllerService; using System.ServiceModel; using System.Web.Security; using System.ServiceModel.Description; namespace HeuristicLab.Services.Optimization.Web.Helpers { public class ControllerServiceHelper { public static readonly string DEFAULT_CONTROLLER_ENDPOINT = Configuration.ControllerEndpointName; public delegate T ControllerServiceDelegate(IControllerService service); private string pw; public ControllerServiceHelper(string pw) { this.pw = pw; } public bool Valid { get { return pw != null; } } public T withControllerService(ControllerServiceDelegate del) { if (!Valid) return default(T); using (var cf = new ChannelFactory(DEFAULT_CONTROLLER_ENDPOINT)) { var credentialBehaviour = cf.Endpoint.Behaviors.Find(); credentialBehaviour.UserName.UserName = Membership.GetUser().UserName; credentialBehaviour.UserName.Password = pw; var controllerProxy = cf.CreateChannel(); return del(controllerProxy); } } } }