Tuesday, May 08, 2012 11:27 PM
WSDL contracts specify a decimal datatype, and my svcutil.exe proxy generator generates decimal properties that are backed by decimal fields. The problem is, decimals by default cannot parse strings from XML like "6E-7".
The Decimal class itself supports an overload of Parse that allows the user to specify the format of the source string. e.g. NumberStyles.Any or NumberStyles.AllowExponents.
Is there a way I can override how WCF deserializes specific class members, or decimals in general?
Thursday, May 10, 2012 2:48 AMModeratorYou could use XmlSerializer.CanDeserialize method to check whether it can deserialize that xml document contains exponent notation, if it cannot be deserialized, then you need to loop through the xml document and replace the string like "6E-7" to the correct decimal format.
- Marked As Answer by Peter pi - MSFTModerator Wednesday, May 16, 2012 12:42 AM
Thursday, June 28, 2012 5:58 PM
We solved the issue a different way, but our "solution" was flaky.
Seems like that should work, but where do I put that in my code?
I have researched this issue further, and the root cause appears to be that the service I am consuming is running Java 6. In Java 5, somebody at Sun decided to break backwards compatibility with the BigDecimal.ToString() method and return exponent notation instead for values with many decimal places. Java frameworks like Castor, Axis and JiXB have received patches to handle this scenario, calling ToPlainString() instead:
- Marked As Answer by John Alexander Zabroski Thursday, June 28, 2012 5:59 PM