Post by MattI have a remote service that my client calls. The client can be
displayed in German or English. This Culture is set through a User
Setting. When I make a remoting call to the server I need to be able
to tell the service that it should return messages in the clients
CurrentCulture. How can I do that?
You'll have to explicitly pass the culture to the service. You cannot
directly pass a CultureInfo object, but you can pass its invariant name.
Your server methods could take this name and create a CultureInfo object
that specifies the desired culture. Your client can then pass (for example)
CultureInfo.CurrentUICulture.Name.
If you have lots of methods, it could be tedious to pass the culture every
time. You could then choose to make the service stateful (make it remember
the culture set in a previous call) or to remove the server's need or
ability to produce culture-specific messages altogether.
Making the service stateful has quite a bit of impact and stateful services
are a lot harder to use and maintain than stateless services, so think
carefully before doing that.
Making the server culture-agnostic would involve passing only
culture-invariant info to and from the client. For example, instead of
passing plaintext messages:
<operationResponse>
<message>Access denied reading file "recipes.txt".</message>
</operationResponse>
pass structured messages, for example:
<operationResponse>
<accessDeniedError file="recipes.txt" />
</operationResponse>
or:
<operationResponse>
<message id="AccessDenied">
<parameter name="file">recipes.txt</parameter>
</message>
</operationResponse>
On the client side, you can look up the appropriate UI strings through
resource files.
If it's important that resources are centralized, you can of course use a
service for looking up resources, reducing the necessity of passing a
CultureInfo to a single service/method only.
--
J.
http://symbolsprose.blogspot.com