开发者

MVC - Using MVC with WCF

I'm designing an MVC application.

I'm considering using webservices so that multiple deployments of the MVC front end can work off a central database accessed via webservices hosted on a seperate server from the MVC application e.g.

  1. MVC application on one server
  2. We开发者_如何学编程bservices implementing business logic and calling database on another server
  3. A database server

If I go down this route then

  1. The controllers in the MVC app will call the webservices, rather than the database directly

However I'm concerned that under this setup the models in the MVC project will just be placeholder objects with validation attributes in them and I will be missing out on other benefits/cabilitiues of the model.

Are there ways of aligning MVC applications with WCF so that using WCF dosn't mean you lose any of the benefits of MVC


There are conceptually 3 models, though because the tools let us, we often use the same model throughout.

Using WCF does make Separation of Concerns explicit.

There's an Entity Model that defines the physical representation of data in your data store, such as that generated by EF. This is implementation specific.

There's a View Model that represents data in your UI. This is implementation specific.

There's a Domain Model that repesents data logically. This is used as the interface to your WCF services and is not implementation-specific. This allows, for instance, none-.NET clients to consume your services.

It's true that there is a code overhead, but in none-trivial cases, the benefits of further abstraction can be significant.

It allows you to change the implementation of your data access and the implementation of the UI independently and is a good thing.


You are not loosing any benefit. It is about separation of concerns - you are doing that.


Right click the project in the Solution Explorer Choose Add–> Service Reference –> Then click the Advanced Button... –> Then click the "Add Web Reference…" button –> then type the address of your Web Service into the URL box. Then click the green arrow and Visual Studio will discover your Web Services and display them.

How to access a WCF service in an ASP.Net MVC application

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜