Is there DataMember(ContentMaxLength=30) or a like? RRS feed

  • Question

  • Hi,

    I would like to limit the length of string data member fields for my data contracts like one can do in xml schema definitons (xsd).

    This max length information should be visible in the wsdl and find it's way to the generated proxy used to call the service. Maybe I completly miss something and try to do it the wrong way.. how to specifiy such basic a basic thing in wcf data contract?

    Is this possible with the DataContractSerializer or do I have to use the XmlSerailizer? Basically I would like to use the DataContractSeralizer...

    Chris Richner http://www.raccoom.net
    Wednesday, February 18, 2009 2:43 PM


  • This is a side-effect that DataContracts are there to assist with message generation nothing more. There is no declarative way in .NET to say (Length < 30). This is one of those places where the cracks between the .NET and XML worlds show. The only thing you could do for enforcement is to use a message inspector and actually validate against the schema
    Richard Blewett, thinktecture - http://www.dotnetconsult.co.uk/weblog2
    • Marked as answer by Chris Richner Wednesday, February 18, 2009 8:23 PM
    Wednesday, February 18, 2009 3:31 PM