// 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.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; namespace WS.WCF { [DataContract] public class Data { [DataMember] public int Id { get; set; } [DataMember] public string Val { get; set; } public static WS.Data Export(Data o) { return new WS.Data{ Id=o.Id, Val=o.Val }; } public static Data Import(WS.Data o) { return new Data{ Id=o.Id, Val=o.Val }; } } [ServiceContract] public interface IRepoService { [OperationContract] [WebInvoke(UriTemplate="/{id}", Method="GET",ResponseFormat=WebMessageFormat.Json)] Data GetOne(string id); [OperationContract] [WebInvoke(UriTemplate="", Method="GET",ResponseFormat=WebMessageFormat.Json)] List GetAll(); [OperationContract] [WebInvoke(UriTemplate="", Method="POST",RequestFormat=WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.Bare)] void Add(Data o); } }