Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a reason to use WCF over asp.net MVC?

If I am using knockout.js or angular.js for the presentation layer, also assume that the service layer needs to write data and read data from the database and it holds the business rules. Is there a reason why I should use WCF over asp.net MVC for the service layer? Calling an MVC controller that returns JSON data seems pretty simple, I can't think of a reason to use WCF.

like image 422
Foo Avatar asked Sep 14 '13 21:09

Foo


People also ask

When should we select WCF over Web API?

Use WCF to create reliable, secure web services that are accessible over a variety of transports. Use ASP.NET Web API to create HTTP-based services that are accessible from a wide variety of clients. Use ASP.NET Web API if you are creating and designing new REST-style services.

Why should we use WCF service?

Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application.

Can we use WCF in MVC?

In this article, you will learn about consuming WCF service in MVC application, using entity framework. This article includes a step by step tutorial to learn WCF using MVC in Visual Studio. We are also using the Entity Framework (. edmx model) for database operations.

Does ASP Net Web API replace the WCF?

No, it's not true that ASP.NET Web API has replaced WCF. WCF was generally developed to develop SOAP-based services. ASP.NET Web API is a new way to develop non-SOAP-based services such as XML, JSON, etc.


3 Answers

If you are specifically targeting the web stack, ASP.NET MVC + WebApi would be the right combination on the server side.

The inherent support for JSON on both client and server makes a JSON-based API very popular. More and more public APIs from most of the providers are JSON-based or at least support JSON.

WCF may have its applicability in terms of server-to-server communications but for a web stack, I don't think it's a good fit. If you have a requirement to support multiple transport mediums, bind with protocols other than HTTP, support binary serialization for performance, complex security requirements, then WCF can help you.

Also for JSON based API, I suggest you use WebApi instead of using MVC and returning a JsonResult.

like image 147
Chandermani Avatar answered Nov 03 '22 22:11

Chandermani


The point in WCF is to separate the means of getting the content from the logic itself. This would be helpful if you at a later point decided to re-use this logic for something that required a SOAP interface, or a binary binding.

If you use MVC, and you hard-code JSON as your output in your view layer, then you are tied to using that for your over the wire protocol. Plus, you will have to write a lot more of your object's JSON serialization yourself.

A lot of it depends on how you are structuring your services, and where you intend to put the flow control for your application. For example, say you are submitting a form to save some content. After the content is saved, do you intend to have the control over where to go next encoded (success or failure) into the client? Or do you want to handle that routing decision on the server?

If it's client-based, then WCF is probably more appropriate, as you are actually moving the controller and the view layers into the client. And the server-side services are purely business and data services, really they are the "domain model".

If you want to control it server-side, then MVC is more likely what you are looking for, as you need a controller, and the "view" layer is split between the client and the server. But the client will have to be written in such a way that it respects what the server is telling it to do. The client becomes a dumb renderer, and the server tells it when to go to a new page.

like image 34
Rob Conklin Avatar answered Nov 03 '22 22:11

Rob Conklin


I would use WCF over MVC simply because with WCF, if you write a proper BO layer, you can easily access that layer from mobile, workflow, winform, etc.etc.etc. all you want. MVC is going to lock you into the paradigm of controllers for actions. I do all of my enterprise scale n-tier apps with WCF (usually exposing both soap and rest bindings) from the same business objects which gives maximum flexibility.

like image 43
Allen Avatar answered Nov 03 '22 21:11

Allen