.net – Setting CultureInfo on wcf service calls

cultureinfonetwcf

I have a WCF service running that needs to parse some data. It turns out that data (points, sizes) gets converted differently in different CultureInfo's and the parsing is spread out in a lot of classes and methods. Since all the parsing is done without passing any CultureInfo the success of the parsing is dependant of the threads culture.

Since there is no programmatic setting of CultureInfo the service picks the current cultureinfo off the machine somehow. I have no idea where it gets this, since changes to the Regional and Language Options doesn't seem to have any effect on the cultureinfo of the wcf service. Also changes to the web.config (yes the service is hosted in iis) doesn't seem to work either.

Am I really left with only one option? Setting the CultureInfo programmaticly? I could find all the conversion calls and pass in a CultureInfo or i could set it on the Thread.CurrentThread.CurrentCulture. Is there no way i can set the CultureInfo once and for all – having effect on all the exposed wcf methods?

Best Answer

The answer about using tag in web.config only works if Asp.net compatibility mode is enabled. You also need the following inside :

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>

Without Asp.Net compatibility mode, the http modules are not used and the tag is ignored.

Related Topic