Gareth
Gareth

Reputation: 2484

Is it possible to set the max-length of a data member in WCF

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...

Upvotes: 6

Views: 5913

Answers (2)

Darryl Windsor
Darryl Windsor

Reputation: 109

I guess this post is old but it now exists just add the Maxlength attribute

[MaxLength(MaxLength = 100)]
public string Name{ get; set; }

Upvotes: 2

marc_s
marc_s

Reputation: 754973

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.

Upvotes: 6

Related Questions