Best practices for incorporating WCF into an MVC middle tier
I was wondering if some one has implemented a 3 tier application using MVC and WCF as the middle开发者_运维技巧 tier? Were there any performance issues/drawbacks rather than implementing a typical middle tier using .dll's. I was envisioning a Middle tier of WCF which would access the DAL (linq to SQL), any advice/links are greatly appreciated!
3 tier application with MVC and WCF generally means:
- Font-end ASP.NET MVC where in simplest scenario controller calls proxies of WCF services.
- Back-end/middle-tier WCF exposing your business logic / data access
- Database server hosting your database
Where should you use this? Only when you really have to - you have strict requirement for that. This of course has huge performance impact because front-end uses remote call for every business operation. Remote call can be either between processes on the same machine but most often to the process on another server (in another network). It also requires better design of interactions to reduce number of calls to minimum as well as using asynchronous communication to invoke multiple calls in the same time if needed.
If you develop the web site which intensive use AJAX (per jQuery.ajax for example) you can implement it in the following way:
- Front-end can be made with respect of ASP.NET MVC. The data for the corresponding Views will be requested per AJAX.
- WCF published on the same wed site as the ASP.NET MVC (see here an example) can provide JSON data for all AJAX requests. WCF can be seen as middle tier component which implement the business logic and get the data needed from the database server.
At such architecture of the application the ASP.NET MVC will be reduced to V (Views) using master pages. It can be generated different views depend on the user roles. The Model and the most Controller actions will be moved in the WCF. WFC methods could be tested with unit tests exactly so good as controller actions. If you will need some other data like dynamically generated pictures (Charts for example) or dynamically generated Excel or WinWord files you can return all the data from WFC methods exactly so easy like you can do this from the MVC controller actions.
At such design of your application I see no performance or other disadvantages. Both View of ASP.NET MVC and WFC have many caching possibilities which you can use on demand.
精彩评论