简体   繁体   中英

Silverlight - How do you localize calls to WCF service?

I'm currently trying to find good way to make calls to WCF services in a way that will allow Thread on server to be aware of client culture. After spending couple days reading topics on the web it seems to me that the best way to do this is just to add (string clientCulture) to list of parameters of WCF methods; no longer:

string HelloWorld();

but:

string HelloWorld(string clientCulture);

I hope I am wrong... and I welcome any suggestion that would show me how to do this better. Ideally I would be able to do following:

WcfService srv = new WcfService();
srv.Endpoint.Address = new System.ServiceModel.EndpointAddress(
    ConfigConstants.ROOT + "Services/WcfService.svc");
// influence address as you are influencing address
srv.Culture = new System.Globalization.CultureInfo("fr-FR");
// and every call to server from now on would pass that 
// culture parameter either in header or body of SOAP message to server

Thanks in advance for any help on this topic!

The brute-force way would be as you say, to add a parameter with the client culture which you would pass with each call.

However, a more elegant solution would be to create a behavior on the client and on the server side.

The client-side behavior would add a header to the request in the client, getting the current culture from the CultureInfo class.

The server side behavior would look for the header in the message, and add it to a the OperationContext, with a known key, which can be retrieved on the server-side call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM