Unable to change Culture in WCF
iis-7, wcf, web-config
Solution
The WCF will ignore your globalization configuration if you do not set aspNet compatibility:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
...
To use that mode your service class must have the attribute AspNetCompatibilityRequirements set to Allowed or Required:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ServiceClass
{
...
}
This could work if you want to apply the Culture and CultureUI from config file.
Or you could either try to force the Culture in your WCF service code, if you are sure that it will not change dynamically. For instance, in your service class constructor. Note that this is not a best practice, perhaps you should use a Context initializer, but this one is quite simple.
public ServiceClass()
{
...
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-AU");
System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-AU");
}
More info:
setting-cultureinfo-on-wcf-service-calls
using-call-context-initializers-for-culture
Problem
I'm running on a windows 2008 server. I have one Web service which calls a wcf service. Within the WCF service it attempts to cast a date 20/08/2010 which fails because it thinks it in US format not Austrlaian. So far I have: - On control panel change the region to English Australian under format - Under the Administrative tab I have also set system local to English (Austrlian) - within IIS7 at the default web site level I have changed Culture and UI culture under the .Net globalization. - I've also done this at the Web service and WCF Nodes I have added the following to the Web service and WCF apps web.config file ``` <globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="en-AU" uiCulture="en-AU" /> ``` This finally changed the culture in the Web service but the WCF service remains US culture. Can anyone tell me what else I can try?