WebOperationContext.Current hg clone https://hg01.codeplex.com/wcfInstall-Package WebApi.All1 [ServiceContract] 2 class TheService 3 { 4 [WebGet(UriTemplate = "time")] 5 HttpResponseMessage TheOperation(HttpRequestMessage req) 6 { 7 return new HttpResponseMessage() 8 { 9 StatusCode = HttpStatusCode.OK, 10 Content = new StringContent( 11 DateTime.Now.ToLongTimeString()) 12 }; 13 } 14 }
ServiceContract is just a container for operationsWebGet[UriTemplate="..."], orWebInvoke[UriTemplate="...", Method="..."] 
HttpRequestMessageHttpRequestMessage<T>UriTemplate = "time/{zone}"HttpResponseMessageHttpRespondeMessage<T>1 class Program 2 { 3 static void Main(string[] args) 4 { 5 using (var host = new HttpServiceHost(typeof(TheService), 6 "http://localhost:8080")) 7 { 8 host.Open(); 9 Console.WriteLine("Host opened at {0} , press any key to end", 10 host.Description.Endpoints[0].Address); 11 Console.ReadKey(); 12 } 13 } 14 }
HttpServiceHostHttpBindingRouteCollection extension methods1 public class Global : System.Web.HttpApplication 2 { 3 protected void Application_Start(object sender, EventArgs e) 4 { 5 RouteTable.Routes.MapServiceRoute<TheService>("base_path"); 6 } 7 }

HttpRequestMessageHttpResponseMessage asynchronoslyHttpParameter setsHttpParameter sets

HttpRequestMessageURITemplate bound variables 
HttpRequestMessage<T> or a content model`HttpRequestMessage<T> or a content modelMediaTypeFormatter - conversion between the HTTP body and the content modelHttpHostConfiguration configuration builderHttpConfigurableServiceHost service hostRouteCollection extension methods receiving the configuration1 var cfg = HttpHostConfiguration.Create() 2 .AddMessageHandlers(typeof (SampleMessageHandler)) 3 .SetOperationHandlerFactory(new MyOperationConfigurationFactory()); 4 5 var host = new HttpConfigurableServiceHost(..., cfg, ...){ 6 7 class MyOperationConfigurationFactory : HttpOperationHandlerFactory{ 8 override Collection<HttpOperationHandler> 9 OnCreateRequestHandlers( 10 ServiceEndpoint endpoint, 11 HttpOperationDescription operation){ 12 var coll = base.OnCreateRequestHandlers(endpoint, operation); 13 coll.Add(new LoggingOperationHandler(operation)); 14 if (operation.Name == "GetTimeString") 15 { 16 Formatters.Remove(Formatters.XmlFormatter); 17 Formatters.Remove(Formatters.JsonFormatter); 18 Formatters.Add(new WaveFromTextFormatter()); 19 Formatters.Add(new ImageFromTextFormatter()); 20 } 21 return coll; 22 } 23 }
