Had a very frustrating problem the other day when trying to use a service proxy that I had generated via svcutil.exe. The symptom was that some of the properties that I was setting on my proxy objects were not being serialized to the message that was being sent via my WCF binding.
The short answer is that some of the properties in my objects had some associated properties that needed set. Take these two properties for example:
1485
1486 /// <remarks/>
1487 [System.Xml.Serialization.XmlAttributeAttribute()]
1488 public bool definitive
1489 {
1490 get
1491 {
1492 return this.definitiveField;
1493 }
1494 set
1495 {
1496 this.definitiveField = value;
1497 }
1498 }
1499
1500 /// <remarks/>
1501 [System.Xml.Serialization.XmlIgnoreAttribute()]
1502 public bool definitiveSpecified
1503 {
1504 get
1505 {
1506 return this.definitiveFieldSpecified;
1507 }
1508 set
1509 {
1510 this.definitiveFieldSpecified = value;
1511 }
1512 }
As you can see, when svcutil created the property for the "definitiveField" property in the XML schema, it also created a "definitiveSpecified" field. If you leave the *Specified field left to it's default value (false), the property will not serialize and you'll be left scratching your head.
Why?
It turns out that if the XML schema defines a property as optional using "minOccurs=0" (or you could think of it as 'nullable'), then the .Net XMLSerializer will not serialize the default value for the property. It makes sense - you wouldn't want the framework to assume that you want the default for a particular value... but nevertheless - this is a major gotcha.