none
MVC CurrentCulture WebService RRS feed

  • Question

  • Hello,

    I'm debugging a MVC web application which calls an external WebService method.

    When I set a breakpoint on the MVC app, the CurrentCulture is nl-BE. But when I break at the WebService method the CurrentCulture is empty (invariant). This gives me a faulty date format.

    When I add the following line to Web.Config, the CurrentUICulture is set, but the CurrentCulture remains empty.

    <globalization culture="nl-BE" uiCulture="nl-BE"/>

    I don't understand why the Culture changes on the WebService side. Can anybody explain this to me, please?

    Why can I set the CurrentUICulture, but not CurrentCulture using the globalization tag in Web.Config?

    Grtz,

    B

    Thursday, March 6, 2014 8:28 AM

Answers

All replies

  • Hi Bruno,

    >I don't understand why the Culture changes on the WebService side. Can anybody explain this to me, please?

    Did you mean you receive a faulty date format from the external web service method? The CurrentCulture property of web service’s default value is the operating system’s User Locale, it’s possible that is will return another culture to you.

    If you control the web service, you can change the CurrentCulture at runtime. For more information, see the following link. http://stackoverflow.com/questions/7893108/how-to-dynamically-initialize-culture-in-asp-net-webservice-call.

    If you don’t control web service. Never mind, we can use the following code to convert datetime.

    date.ToString(new CultureInfo("nl-BE"))

    Hope useful.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, March 7, 2014 2:55 AM
    Moderator
  • I have control of the web service. It's all running on the same (local) machine, so I can step into the code of the web service (it's just an other solution). My machine's culture is set to nl-BE.

    That's why I don't understand, that the web service is showing invariant culture.

    the web service has a date value that is put in a string, something like

    string.Format( CultureInfo.CurrentCulture, "blabla {0} bla", date.ToShortDate());

    The string returned by the web service will have a date format of that CurrentCulture (that for a reason I don't understand is not my machines culture like I would expect)

    Friday, March 7, 2014 9:12 AM
  • Hi Bruno,

    I build an ASP.NET project to test your question. I add globalization to web.config file and set the two properties to nl-BE. It works fine when I call the web service. I think there may be some wrong with your computer.

    Please add the following link to your web service and see the result.

    [WebMethod]
    
            public string HelloWorld()
    
            {
    
                return System.Threading.Thread.CurrentThread.CurrentCulture.ToString() + "  " + System.Threading.Thread.CurrentThread.CurrentUICulture.ToString();
    
            }
    

    Configuration in web.config

    <globalization culture="nl-BE" uiCulture="nl-BE"/>

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 10, 2014 8:39 AM
    Moderator
  • I already did that, and the CurrentCulture is empty, while the CurrentUICulture = nl-BE.

    That's what I don't understand. The UICulture is set, but not the Culture.

    I checked the suggestion in the following post on stackoverflow. All .config files on my machine look fine, there are no Page directive attributes and no InitializeCulture override anywhere. The only thing I could think of are the Assembly attributes, which are set by default because it's a generated file in Visual Studio. Default they're empty [assembly: AssemblyCulture( "" )], but adding [assembly: AssemblyCulture( "nl-BE" )] didn't do anything for me.

    It's all a big mis(t)ery to me :(


    Monday, March 10, 2014 9:47 AM
  • Hi Bruno,

    It’s strange that the CurrentCulture is empty. I cannot find any reason that CurrentCulture will return empty. I think maybe there is something wrong with the computer.  Can you build a new project and web service in another machine, and see if it will return empty?

    http://stackoverflow.com/questions/13359141/can-cultureinfo-currentculture-ever-be-null.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 14, 2014 6:04 AM
    Moderator
  • I'm so embarrassed. Turns out somewhere deep in the code the culture was set to invariant, because dates must always be written as invariant to the database.

    I did not get a memo :(

    Thanks for your time.

     
    Wednesday, March 26, 2014 2:04 PM
  • You are always welcome.

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, April 1, 2014 6:43 AM
    Moderator