How does ASP.NET MVC relate to WCF?

A guide to designing and building RESTful web services with WCF 3.5 , this article explains the basics of REST and their relationship to WCF. MVC uses REST as its architectural model. I'm guessing it is possible to use .NET MVC to create web applications that have both an interface and an API point, but I'm not sure if the safe way to create an API is to build it with WCF and then use it in MVC as a controller ...

Please comment, if the question is not clear, I will add or change the text.

+2


source to share


3 answers


This is actually the third option, ADO.NET Data Servies. Anyway, this is how I see them.

MVC REST: gives you full control over how to expose your data, you need to write all the code to run it for example. serialization, deserialization, all CRUD methods, etc. etc. Worht believes this is an MVC site means you are limited to providing your service over IIS over HTTP (S)

WCF REST: More automation than MVC, much more robust frameowkr than MVC REST i.e. caching, security, error handling, etc. (basically all the stff you will have to write yourself using simple MVC). Being WCF, you can host it in various ways (e.g. WS-, TCP), etc.



ADO.NET DATA SERVICES: The fastest way to get everything up and running, all you need to do is to set up global.asax, however you need to use an entity data model which you many don't want.

Personally, I would like to use either ADO.NET DATA SERVICES or WCF REST to create an API, expose that API to an MVC site, and then expose this API directly or pass it through another layer.

+2


source


ASP.NET MVC can serve as a REST endpoint for working with lightweight services, so I think the answer to your question depends on how you define "secure".

Obviously, WCF is designed specifically for creating REST endpoints with all the security implications it entails, while ASP.NET MVC is designed to create REST endpoints that ASP.NET MVC itself can use.

The following article demonstrates how to create a web service using an ASP.NET MVC controller:

Create REST API using ASP.NET MVC that speaks both Json and plain Xml http://msmvps.com/blogs/omar/archive/2008/10/03/create-rest-api-using-asp-net -mvc-that-speaks-both-json-and-plain-xml.aspx




See also the following article by Phil Haack, which discusses the SDK that the WCF team put together for ASP.NET MVC users:

Rest for SDK and ASP.NET MVC Sample
http://haacked.com/archive/2009/08/17/rest-for-mvc.aspx

+1


source


These are two different sets of technologies related only to building on .net

MVC is used to build websites and provides a model where URLs are routed to controllers and controllers deliver views to the user as a UI.

WCF is a set of libraries in .net that are used for an abstract type of service (hosted in a Windows service, as a web service in IIS, etc.) and in a protocol (HTTP, TCP, MSMQ, etc.) ) from client and server that exchange data.

An MVC website can use WCF to connect to a web service, but this is just one of many options.

-1


source







All Articles