xs:integer problem in data contracts generated from xml

Topics: July and December Releases Forum
Mar 16, 2007 at 2:48 PM
I used "Create XML Serializable type from schema" recipe in WCF to generate data contract classes from xsd files. Most of the fields are correct, except for the ones defined like this one: <xs:element name="XYZ" type="xs:integer" />. This property was generated in the class as following:
public string XYZ

I checked other elements with type = "xs:decimal" defined in xsd and they were generated as decimal correctly in the class. Is there any explanation for this?

Mar 16, 2007 at 8:04 PM
If you want to generate an "Int" CLR Type, the you should have an "int" DataType value defined in your schema.
This catch goes like this:
The CLR types that maps to schema types don't in all cases match the CLR types that the XmlSerializer maps to schema types. The schema reader says that "xs:integer" maps to System.Decimal. That's consistent with the XmlSchema part 2 spec. However, the XmlSerializer used in that recipe says that "xs:integer" must map to a System.String. The same goes to "xs:gYear", and several others.
I know that this is an XmlSerializer issue but you may post this as an issue for the next release of the WSSF in order to consider these differences and act accordingly before generating the code.

Mar 22, 2007 at 1:21 PM