Code Renaissance is about building great teams and great software. By exploring best practices, team interactions, design, testing and related skills Code Renaissance strives to help you create the team and codebase that you've always wanted.

Problem serializing WSDL generated properties where minOccurs equals zero

A colleague brought me a problem that had us both stumped. He had a WSDL generated class that, when serialized, was missing several properties in the XML. He'd found something in common with between the missing properties though: all of the missing properties had minOccurs=0 set in the WSDL. The problem was that we didn't see any difference between the properties generated with and without the minOccurs zero setting; they seemed to generate the same code.

After a bit of google-gymnastics I found a stack overflow post that detailed the problem. When minOccurs is set to zero for and element WSDL.exe rightly considers the element optional. To handle these optional elements it generates two properties in the class: myProperty and myPropertySpecified. If you choose to set a value for the optional property then you must indicate that you've done so by also setting the specified property. When you do everything serialzes just fine.

Hope this helps.