Validation WebService

Validation WebService

Old forum URL:

jairan posted on Tuesday, October 01, 2013

Validation rules of the attributes do not work with webservice.



Ex :

BusinessRules.AddRule(new Required(CodPrestadorOperadoraProperty));


The field is required, but when I save generates the error 



" Object is not valid and can not be saved "

JonnyBee replied on Tuesday, October 01, 2013

I do not understand the actual issue here. 

If the field has no value then the rule is broken, the object will have IsSavable = false and the Save method will give that exception. 

Can you provide more details and code? 


jairan replied on Wednesday, October 02, 2013

Hello Jonny,

This attribute is mandatory, the time I save should not prevent action stating that there is a required field and that it was not filled.



  Protected override void AddBusinessRules()



            BusinessRules.AddRule(new Csla.Rules.CommonRules.Required (CodPrestadorOperadoraProperty , () => "Codigo Obrigatorio." )  );

            BusinessRules.AddRule(new MaxLength(CodPrestadorOperadoraProperty, 10));

            BusinessRules.AddRule(new MinLength(CodPrestadorOperadoraProperty, 2));




//// Save

_Eleg.CodPrestadorOperadora = null; 

_Eleg = _Eleg.Save();  





jairan replied on Wednesday, October 02, 2013


Using the WinForm, usually works.

Now the WebService that this rule does not bar.

jairan replied on Wednesday, October 02, 2013



When I use the "ErrorProvider", know what the error is.


When not use, do not know what error is.

JonnyBee replied on Wednesday, October 02, 2013


The business object is not aware of any type of UI or Service.
Csla is for business objects and not just data access code. 

If the object has broken rules with severity ERROR the object is considered broken and you are not allowed to call Save. 

An alternative is to change the Severity to Warning or Information. Any broken rule with these severities will NOT block Save operation. 

jairan replied on Wednesday, October 02, 2013


Thank you Jonny for the clarifications

Copyright (c) Marimer LLC