0

I have a service method that accepts CultureInfo object as a parameter. I want to use it to get correct strings from Resources by the language that was specified. So I have a method on the service like:

public string GetTranslatedString(CultureInfo c)

And on the client I call this method like this:

ServiceReference.GetTranslatedString(CultureInfo.CurrentUICulture);

I've also tried:

ServiceReference.GetTranslatedString((CultureInfo)CultureInfo.CurrentUICulture.Clone());

But it produces incorrect results! The culture info object gets passed as if it was describing culture of PC where the service is, not the culture of the PC where the client is. So if the client has "nl" culture, the server still gets "en" culture! Why? I know how to solve this issue otherwise by passing LCID to the service instead of the object, but I really want to know why the described approach doesn't work.

Bogdan Verbenets
  • 25,686
  • 13
  • 66
  • 119
  • Have you used the debugger to make sure you're passing what you think you're passing from the client? I'm not sure how CultureInfo gets parsed into WSDL either. Maybe there's some problem with that? In general, try to pass interoperable stuff over the wire. – Tad Donaghe Nov 29 '11 at 15:46
  • Can you also provide the code where the CultureInfo object is created by the client please? – Talvalin Nov 29 '11 at 15:53
  • @Talvalin CultureInfo.CurrentUICulture is a static property. I don't know how it is initialized. – Bogdan Verbenets Nov 29 '11 at 15:59
  • @TerryDonaghe please read my comments to jrb's answer. – Bogdan Verbenets Nov 29 '11 at 16:18

1 Answers1

1

Try this (just 4 fun):

CultureInfo ci = CultureInfo.CurrentUICulture;
string text = ServiceReference.GetTranslatedString(ci);
jrb
  • 1,708
  • 2
  • 13
  • 20
  • I don't know why it works, but it works! Can anyone explain me why? By the way, passing CultureInfo.CurrentUICulture.Name and CultureInfo.CurrentUICulture.LCID without assigning them first to some sort of variable as shown in this answer also doesn't work and produces incorrect results as in my question! – Bogdan Verbenets Nov 29 '11 at 16:15
  • For me this did only work when setting `` and `` in web.config! – Daniel Calliess Jul 26 '17 at 08:07