2010-02-28 27 views
4

我目前正試圖找到一種好的方式來調用WCF服務,這樣可以讓服務器上的線程知道客戶端文化。花了幾天在網上閱讀主題後,我認爲最好的方法是將(string clientCulture)添加到WCF方法的參數列表中;不再:Silverlight - 你如何將調用本地化到WCF服務?

string HelloWorld();

但:

串的HelloWorld(串clientCulture);

我希望我錯了...我歡迎任何建議,告訴我如何更好地做到這一點。理想情況下,我將能夠做到以下幾點:

 
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 

在此先感謝您對此主題的任何幫助!

回答

1

蠻力的方式就像你說的那樣,爲每個呼叫傳遞的客戶文化添加一個參數。

但是,更優雅的解決方案是在客戶端和服務器端創建行爲。

客戶端行爲會在客戶端的請求中添加一個頭,從CultureInfo類中獲取當前文化。

服務器端行爲將查找消息中的標題,並將其添加到OperationContext中,並使用已知密鑰在服務器端調用中檢索該密鑰。 「因爲它不支持的行爲 -

+0

聽起來不錯......現在知道怎樣使用Silverlight實現它? – kape123 2010-02-28 19:54:45