Is it possible to set a requirement in WCF that a specific string datamember have a maximum length?
I'm essentially wanting to do some basic validation, and enhancing the implicit documentation that WSDL gives you.
I'm pretty sure that its possible when writing raw WSDL, but am not sure if you can do it in WCF using attributes etc.
And related, require that an array property have at least one element in it...
No, to my knowledge, that's not possible - at least not yet. There is that concept of Data annotations floating around, being supported by ASP.NET dynamic data and now also by the Silverlight RIA Services, but in "pure" WCF, I don't know of any such means of limiting the length of a string in your DataContract, or requiring an array to have at least one members.
At least not in a declarative way (i.e. with attributes on your data contract).
There are a few things you can do on the data contract, like require an attribute to be present and such, but those are very limited in scope.
I guess this post is old but it now exists just add the Maxlength attribute
[MaxLength(MaxLength = 100)]
public string Name{ get; set; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With