Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

You should check out this blog post...

http://blogs.msdn.com/drnick/archive/2008/02/26/using-call-context-initializers-for-culture.aspx

... which shows how to define a behaviour for setting the culture.

HOWEVER, web.config should be your friend here. You should be able to set up the "default" culture that your service works with from here.

The globalization elemenent...

http://msdn.microsoft.com/en-us/library/hy4kkhe0.aspx

... should allow you to set the Culture and UICulture...

<globalization
    enableClientBasedCulture="true|false"
    requestEncoding="any valid encoding string"
    responseEncoding="any valid encoding string"
    fileEncoding="any valid encoding string"

    responseHeaderEncoding = "any valid encoding string" 
    resourceProviderFactoryType = string
    enableBestFitResponseEncoding = "true|false"

    culture="any valid culture string"
    uiCulture="any valid culture string"/>

You can use the config file as Martin mentioned above but as good practise you should definitely set the culture info wherever necessary to InvariantCulture to cater for data thats being sent through in different locales. ie dates, strings, numbers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top