Home > .NET > WCF localization

WCF localization


In a previous post i wrote about jquery treeviews created with a WCF service.

I have discovered that the localization does not work ,the Thread.CurrentThread.CurrentCulture at runtime is the one of the Windows Control panel .

I order to work correctly with the language you set in the site , tipically with this code

Thread.CurrentThread.CurrentUICulture = new CultureInfo(strLang);
Thread.CurrentThread.CurrentCulture = new CultureInfo(strLang);

in the web.config must be added the line

<serviceHostingEnvironment aspNetCompatibilityEnabled=”true”/>

Immediately under the node


But this is not enough, because now we are reading the browser default language : so if we are setting the Culture with Session variables we must use something as

Thread.CurrentThread.CurrentUICulture = (CultureInfo)HttpContext.Current.Session["UILang"];
Thread.CurrentThread.CurrentCulture = (CultureInfo)HttpContext.Current.Session["Lang"];

In the WCF code.

Categories: .NET
%d bloggers like this: