WCF Data Services (OData) Vs ASP.NET Web API

后端 未结 8 629
鱼传尺愫
鱼传尺愫 2021-01-29 21:01

I am designing a distributed application that will consist of RESTful services and a variety of clients (Silverlight, iOS, Windows Phone 7, etc). Right now I\'m determining whi

8条回答
  •  天涯浪人
    2021-01-29 21:37

    Both Web API and WCF Data Services support OData out of the box. With WCF Data Services (WCFDS), it's automatic. With Web API, return IQueryable from your controller and tag the method with [Queryable]. This will get you the $filter functionality you were talking about. And if you go about it this way, both can handle JSON in the response automatically by putting accept=application/json in the request header. The OData from WCFDS supports a few more OData keywords than the Web API (although only the $expand keyword comes to mind), but I'm sure time will remedy this.

    Both .NET clients and HTML pages can call into both of these alternatives easily, but if you like LINQ, and you are building .NET clients, WCFDS can be added into your project as a service reference. This allows you to skip all of the HTTP business altogether and directly query the collections.

    The bottom line is that there is nothing preventing you from putting .svc files into your ASP.Net MVC project. It isn't an either-or proposition. Adding data services to your server will save you the need to write lots of controllers, but doesn't prevent you from writing additional controllers if you wish.

提交回复
热议问题