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:
W开发者_JAVA百科cfService 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.
http://www.codeproject.com/Messages/3385580/Adding-custom-headers-to-Silverlights-WCF-calls.aspx
精彩评论