How to define the culture in a WCF Webservice?

Asked

Viewed 674 times

6

I have a plea WCF rotating in the IIS where the server language/culture is all defined in English.

There is no possibility for me to change the server settings so that I could change the culture or language of the server. I would need an application-level solution.

I tried to use in the Web.config the same configuration that is used when you want to do this for applications ASP.NET but apparently the WCF does not read this setting:

//Diminuído para brevidade
<configuration> 
    <system.web>  
        <globalization culture="pt-BR" uiCulture="pt-BR" />
    <system.web> 
<configuration> 

Has anyone ever had this problem that can help me solve?

  • I don’t know the architecture of your system, nor am I an expert in WCF to formulate a complete answer... But shouldn’t culture handling be restricted to the application interface? If there isn’t even a way to set this up in the Communication Foundation libraries, I even understand why.

  • In the above case the context is the creation of a WebService, then there is no interface. It would be consumed by another application. In an analogy you can consider a API to be consumed by another application.

1 answer

3

If you only use HTTP, you can activate the property aspNetCompatibilityEnabled, so WCF will read the settings of globalization.

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>

This will cause your WCF to run on the same ASP.NET pipeline, which will make it impossible to use other non-ACS protocols.

More information on MSDN

  • Sheltered by the answer. But adding compatibility with ASP.NET causes many changes to be made. Starting with the fact that the service goes through the whole Pipeline of ASP.NET and in this case there should also be loss of performance. But surely this is the solution for cases where compatibility is used.

  • True, it must look worse.

  • I believe the answer lies in configuration hell of WCF. But it’s always hard to move there.

  • Ever tried to use System.Threading.Thread.CurrentThread.CurrentCulture = &#xA; new System.Globalization.CultureInfo("pt-BR"); ?

  • This works William. But I was really looking for a more configurable answer. I understand that I can put something on Web.config and set in this same code but I believe there is some solution that goes entirely in the configuration file. Your answer stands as the best qualified for "V" so far ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.