简体   繁体   中英

Passing WCF validation to mvc client side without duplicating

I am working on a project where there is existing WCF (with data annotation validation) which will be use in MVC project. We would like to make the data annotation validation as in WCF to be able to work in MVC client side without duplicating any validation logic and inherit any class in MVC. By default, jquery unobstructive validation will do the rest for us in client side if the model is written in MVC but not the case when WCF chips in.

Our team has been cracking our way to get this done but unfortunately we have not found any elegant solution. However, we would thought that this will reduce much amount of work to refine the presentation layer every time the backend changes if this could be done.

Maybe we are trying to achieving something that is too good to be real, but we appreciate if someone that has went through/research on this path can give us some hint/advice on this.

Note: no duplicating domain model in presentation/any other layer.

Maybe you can make use of Enterprise Library Validation Application Block (EntLib VAB). So instead of defining the validation rules in data annotation you can define the validation ruleset in EntLib VAB. You may also use the same validation rule in both WCF and MVC application. Maybe you just need to write a middle layer in your MVC application that translates the EntLib VAB ruleset to MVC data annotation ruleset. And as long as this translation is correct and in line with the available data annotation validation in MVC you don't even have to write client side data validation adapter.

This is not easy way of doing it, but it saves the duplication of POCO classes in WCF and MVC web app. Also if you can setup the 'framework' properly it may proved to be useful in future in terms of setting up new rules and so.

In case, you like this idea, you may want to check this: http://programersnotebook.blogspot.de/2014/03/extending-enterprise-library-entlib.html http://programersnotebook.blogspot.de/2014/03/extending-entlib-vab-part-1-enable.html http://programersnotebook.blogspot.de/2014/04/extending-entlib-vab-part-21-create.html http://programersnotebook.blogspot.de/2014/04/extending-entlib-vab-part-22-enable.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM