WCF服务有错误的文化
-
25-10-2019 - |
题
我有一种服务方法,将CultutInfo对象作为参数。我想使用它通过指定的语言从资源中获取正确的字符串。因此,我对服务有一种方法,例如:
public string GetTranslatedString(CultureInfo c)
在客户上,我称此方法为这样:
ServiceReference.GetTranslatedString(CultureInfo.CurrentUICulture);
我也尝试了:
ServiceReference.GetTranslatedString((CultureInfo)CultureInfo.CurrentUICulture.Clone());
但这会产生不正确的结果!文化信息对象被传递,就好像在描述了服务所在的PC文化,而不是PC的文化。因此,如果客户有“ NL”文化,服务器仍然获得“ EN”文化!为什么?我知道如何通过将LCID传递到服务而不是对象来解决这个问题,但是我真的想知道为什么所描述的方法不起作用。
解决方案
尝试这个(只有4个乐趣):
CultureInfo ci = CultureInfo.CurrentUICulture;
string text = ServiceReference.GetTranslatedString(ci);
不隶属于 StackOverflow