WCF Web HTTP Example
This example illustrates a straightforward way to create a WCF WebHttp contract using generics Platform: .NET 4 There are two contracts you can use
- IReadOnlyWebEntity
- IWebEntity
[ServiceContract]
public interface IReadOnlyWebEntity<out T> where T : class
{
[WebGet(UriTemplate = "/{id}")]
T GetItem(string id);
[WebGet(UriTemplate = "/")]
IEnumerable<T> GetItems();
}
[ServiceContract]
public interface IWebEntity<T> : IReadOnlyWebEntity<T> where T : class
{
[WebInvoke(Method = "POST")]
void AppendItem(T item);
[WebInvoke(Method = "PUT", UriTemplate = "/{id}")]
void PutItem(string id, T item);
[WebInvoke(Method = "DELETE", UriTemplate = "/{id}")]
void DeleteItem(string id);
}
|