3

I am building a WCF Client with VS2010. The web service we consume defines some data that it returns as xs:nonNegativeInteger. However VS2010, upon generation of the WCF client code, generates classes with properties of type string for these xs:nonNegativeInteger attributes.

I am wondering why that's the case and if and how I can tell VS2010 to adjust its mappings from xs:nonNegativeInteger to integer rather than string.

(I can't change the wsdl of the web service we consume... And I am also hesitant of simply changing the generated code in case we need to update the service reference, so some sort of data type mapping via a config would be ideal.)

Thanks all!

Example snippet of the WSDL we consume:

<xs:element minOccurs="0" name="blub" type="xs:nonNegativeInteger" />

Example snippet of the generated WCF client code:

<System.Xml.Serialization.XmlElementAttribute(DataType:="nonNegativeInteger", Order:=0)>  _

Property blub() As String
spse
  • 284
  • 2
  • 11
  • [Same for all the xs:*integer types](http://stackoverflow.com/questions/9616040/why-does-xsd-exe-generate-string-property-for-xsinteger). – StuartLC Dec 30 '14 at 15:40

1 Answers1

1

It seems you've configured SvcUtil to use the XmlSerializer instead of the DataContractSerializer. MSDN says XmlSerializer will serialize the xs:nonNegativeInteger to string while DataContractSerializer will serialize it to Int64 (search for 'nonNegativeInteger' in each page).

If you don't want to use DataContractSerializer for some reason, your best option is to take advantage of the generated proxy classes being partial classes and create a separate property (either int or long) to encapsulate the conversion logic without affecting how WCF serializes/deserializes that field.

BTW: if that string conversion really annoys you, vote up this issue in CodePlex.

Sixto Saez
  • 12,610
  • 5
  • 43
  • 51
  • Thanks - It seems the integers are unrestricted, meaning the [only valid mapping](http://stackoverflow.com/a/9616162/314291) of the xs:*integer types would be to an arbitrarily large `BigInteger` – StuartLC Dec 30 '14 at 15:46