11

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?

carlosfigueira
  • 85,035
  • 14
  • 131
  • 171
ErickTreetops
  • 3,189
  • 4
  • 27
  • 37

3 Answers3

7

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

Community
  • 1
  • 1
Diana
  • 2,186
  • 1
  • 20
  • 31
2

The problem is in the culture that is set for a user used in the application pool.

I found the following way to resolve this issue:

  1. If the application pools uses ApplicationPoolIdentity change it to NETWORKSERVICE (unfortunatly I didn't found how to set regional settings for ApplicationPoolIdentity)
  2. Set regional settings you need (en-AU) on the current user and than copy them for the system accounts as described here.
Teddy Bo
  • 679
  • 8
  • 19
  • You can use this approach in step 2 to create a new application pool identity that will have the correct culture. When copying the settings select the apply to new accounts check box, reboot, and then create a new app pool. – nuander Feb 26 '15 at 21:14
0

You can do it in the Global.asax.cs file, in the Application_Start file:

using System.Threading;
using System.Globalization;

public class Global : HttpApplication
{
    protected void Application_Start(object sender, EventArgs e)
    {
        CultureInfo.DefaultThreadCurrentCulture = CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-AU");
    }
}
ferhrosa
  • 1,714
  • 2
  • 11
  • 6