How to Migrate from WCF Web API to ASP.NET Web API
Introduction
We recently announced that
WCF Web API is now ASP.NET Web API. This document provides guidance on how to migrate your existing WCF Web API code to ASP.NET Web API.
Overview
The WCF Web API abstractions map to ASP.NET Web API roughly as follows
| WCF Web API |
ASP.NET Web API |
| Service |
Web API controller |
| Operation |
Action |
| Service contract |
Not applicable |
| Endpoint |
Not applicable |
| URI templates |
ASP.NET Routing |
| Message handlers |
Same |
| Formatters |
Same |
| Operation handlers |
Filters, model binders |
Web API Controllers
Update you service types to be web API controllers by first deriving from ApiController and renaming your service type so that the type name ends with "Controller".
Routing
You can directly map URI templates to routes by defining a route that matches the URI template path and then specifying the method name as the default value for the action route variable. The approach will result in one route per action, which depending
on the number of actions may result in significant performance overhead.
To consolidate the number of routes consider refactoring your service so that there is one web API controller per resource.