简体   繁体   中英

Webservice ignores cultureinfo settings of application

I have a webapplication with some forms which are posted to a webservice-method. The json-post is done by the jquery $.ajax method. Although my cultureinfo is set to nl-NL, my webmethod throws an error "10,00 is not a valid value for Decimal.", when posting the values of my form. The same goes for datetimes which have a dutch notation.

It seems like the .net serializer ignores the global culture settings. When i change '10,00' to '10.00' the post is accepted by the webmethod.

We've been struggling with this subject for a while now, couldn't find anything usefull on SO and Google myself. So any help on this matter would be very nice!

So basically this is done due this peace of code:

// No exponent, may or may not have a decimal (if it doesn't it couldn't be parsed into Int32/64)
            decimal dec;
            if (decimal.TryParse(input, NumberStyles.Number, CultureInfo.InvariantCulture, out dec)) {
                // NumberStyles.Number: AllowLeadingWhite, AllowTrailingWhite, AllowLeadingSign,
                //                      AllowTrailingSign, AllowDecimalPoint, AllowThousands
                return dec;
            }

Reference: http://referencesource.microsoft.com/#System.Web.Extensions/Script/Serialization/JavaScriptObjectDeserializer.cs,111a17298608ded3,references

So the only option is to replace the , with the . and surrender to the English supremacy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM