// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Activation; using System.ServiceModel.Web; using System.Web; namespace WS.WCF { [AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Required)] [ServiceBehavior(InstanceContextMode=InstanceContextMode.Single,ConcurrencyMode=ConcurrencyMode.Single)] public class RepoServiceHttpSession : IRepoService { private WS.DataService ds = new WS.DataService(); private void CheckAccess() { if(HttpContext.Current.Session == null || HttpContext.Current.Session["DataServiceAuth"] == null) { throw new Exception("Not authorized"); } } public Data GetOne(string id) { CheckAccess(); return Data.Import(ds.GetOne(int.Parse(id))); } public List GetAll() { CheckAccess(); return ds.GetAll().Select(o => Data.Import(o)).ToList(); } public void Add(Data o) { CheckAccess(); ds.Add(Data.Export(o)); } } }