Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC and WCF

I'm working my way into MVC at the moment, but on my "To learn at some point" list, I also have WCF.

I just wonder if WCF is something that should/could be used in an MVC Application or not? The Background is that I want a Desktop Application (.NET 3.5, WPF) interact with my MVC Web Site, and I wonder what the best way to transfer data between the two is. Should I just use special Views/have the controllers return JSON or XML (using the ContentResult)?

And maybe even more important, for the other way round, could I just call special controllers? Not sure how Authorization would work in such a context. I can either use Windows Authentication or (if the Site is running forms authentication) have the user store his/her credentials in the application, but I would then essentially create a HTTP Client in my Application. So while MVC => Application seems really easy, Application => MVC does seem to be somewhat tricky and a possible use for WCF?

I'm not trying to brute-force WCF in this, but I just wonder if there is indeed a good use case for WCF in an MVC application.

like image 306
Michael Stum Avatar asked Oct 19 '08 22:10

Michael Stum


People also ask

What is the difference between WCF and MVC?

WCF is an inter-process communication mechanism, which means it is used when several processes, either on the same machine or on different machines (client-server applications) need to talk to each other. MVC on the other hand, is a pattern that separates the UI from the back-end logic.

Can we use WCF in MVC?

Since WCF service application and MVC application both are in the same solution, we have to build the Service first and then the MVC application in order to consume the service in MVC application. Do the following for that, Right Click on the MvcWcfEF Solution in Solution Explorer and click on properties.

What is WCF MVC?

What is WCF? WCF stands for Windows Communication Foundation. It is used to create a distributed and interoperable Applications. WCF is an effective platform for developing service-oriented applications.

Is ASP.NET a WCF?

WCF's ASP.NET compatibility mode is suitable for scenarios that do not require the ability to host outside of IIS or to communicate over protocols other than HTTP, but that use all of features of the ASP.NET Web application platform.


2 Answers

WCF services might make sense in this situation, but don't create services that align with your UI, create services that align with the business processes. ie. you won't have a service that returns the view data for each page, you will have a service that exposes logical operations. Then, your site can call the same services that the windows client calls, but you don't have to couple the design of the windows client to the design of the web site.

Instead of this:

Windows Client -> Services -> Web Site

It should be:

Windows Client -> Services

Web Site -> Services

like image 169
jezell Avatar answered Oct 16 '22 08:10

jezell


You could use ADO.NET Data Services to share your data with either JSON (for JavaScript clients) or XML (for desktop applications).

ASP.NET MVC can then take advantage of this by using either of two in the model. As you probably know, ADO.NET Data Services is based on WCF so you were on the right track.

like image 45
jaircazarin-old-account Avatar answered Oct 16 '22 06:10

jaircazarin-old-account