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
It seems you’ve configured SvcUtil to use the
XmlSerializerinstead of theDataContractSerializer. MSDN saysXmlSerializerwill serialize the xs:nonNegativeInteger to string whileDataContractSerializerwill serialize it to Int64 (search for ‘nonNegativeInteger’ in each page).If you don’t want to use
DataContractSerializerfor some reason, your best option is to take advantage of the generated proxy classes beingpartialclasses and create a separate property (eitherintorlong) to encapsulate the conversion logic without affecting how WCF serializes/deserializes that field.BTW: if that
stringconversion really annoys you, vote up this issue in CodePlex.