c# - WCF VAB - How to achieve different validations on the same dto for different service methods? -
i have userdto used request dto in 2 different service methods. 1 called create , other, update.
[operationcontract] [faultcontract(typeof(validationfault))] int create(userdto request); [operationcontract] [faultcontract(typeof(validationfault))] void update(userdto request); for brevity, allow assume below userdto. when service method create called, expect both username , emailaddress validated per validator attributes , works expected. in case of update, want emailaddress validated, username validation should not happen. there way ?
i prefer not write dto there many utilize cases need userdtd , not want repeat same thing in multiple places.
[datacontract] public class userdto { [datamember] public int userid; [datamember] [notnullvalidator] public string username; [datamember] [notnullvalidator] public string emailaddress; }
as know there no way turn off [notnullvalidator] on userdto in update method. can minify duplication doing this:
[datacontract] public class userupdatedto : userdto { [datamember] public new string emailaddress; } void update(userupdatedto request); c# wcf validation
No comments:
Post a Comment