2

I am trying to learn MVC using ASP.NET MVC3. Most of the tutorials I referred are using Entity Framework. In my case , I will be using WCF services for model. I have the following questions (when I am using WCF)

  1. If I am using DataAnnotation for validation, where the validation should be? Is it inside the WCF service?
  2. Is Entity’s used in WCF service be passed as model to view?

Could you please point me to some good MVC3 articles/tutorials that uses WCF and addresses my questions? It would be great if those articles has code demonstrations also.

READINGS:

  1. How to make this Model in ASP.NET MVC3?

  2. WCF AND MVC3, system architecture. Passing a View Model with WCF?

  3. Conditional Validation on MVC3 Model Class

  4. How do I use WCF reference with MVC3 (razor) model?

Community
  • 1
  • 1
LCJ
  • 22,196
  • 67
  • 260
  • 418

3 Answers3

3

If I am using DataAnnotation for validation, where the validation should be? Is it inside the WCF service?

Usually there are 2 levels of validation: one for the view models which are classes that you specifically design for the view and one at the service layer.

Is Entity’s used in WCF service be passed as model to view?

No, you never pass domain models to views. You design view models.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
3

I would strongly recommend against adding DataAnnotation tags on your WCF service.
Rather use a separate view model that is populated from a service/controller that executes your WCF services.


There are two separate concerns here:

  1. Building a view model for your page
  2. Obtaining your model data using a WCF service.
Philip Fourie
  • 111,587
  • 10
  • 63
  • 83
0

Definitely do not use DataAnnotions in WCF. You certainly want layers of abstraction, but How you construct your architecture. Hydrate your models via some form of abstraction. Obviously a repository pattern can fit the bill as you wire up say a generic repository consuming rest/soap wcf services and look at Model vs. ViewModels.

Entity = DDD = Business "?" . Thus e.g. a Product is an entity.

Keeping your validation clean and "DRY" will allow for less coding and more reuse.

Tom Stickel
  • 19,633
  • 6
  • 111
  • 113