Error parse DateTime type param in WebService (asmx file) RRS feed

  • Question

  • User799752452 posted

    Hi All,<?xml:namespace prefix = o /><o:p></o:p>

    <o:p> </o:p>

    I have the following web method:<o:p></o:p>

    <o:p> </o:p>

    <o:p> </o:p>

    <WebMethod()> _<o:p></o:p>

    Public Function GetDate(ByVal dt As DateTime) As String         <o:p></o:p>

    Return dt.Month.ToString<o:p></o:p>

    End Function<o:p></o:p>

    <o:p> </o:p>

    <o:p> </o:p>

    In web.config I defined culture that format date is dd/mm/yyyy:<o:p></o:p>

    <o:p> </o:p>

    <globalization requestEncoding="windows-1255" responseEncoding="windows-1255" responseHeaderEncoding="windows-1255" culture="he-IL" uiCulture="he-IL" /><o:p></o:p>

    <o:p> </o:p>

    (the culture can be "en-GB" ect. ,All culture's DateFormat is dd/mm/yyyy)<o:p></o:p>

    <o:p> </o:p>

    <o:p> </o:p>

    In the client side I call to then web service and send "30/8/2009" to the dt param.<o:p></o:p>

    <o:p> </o:p>

    When I try it in framework 1.1 the response in correctly (status=200), but when I try it in framework 3.5 it response the following exception:<o:p></o:p>

    <o:p> </o:p>

    <o:p> </o:p>

    System.ArgumentException: Cannot convert 30/8/2009 to System.DateTime.<o:p></o:p>

    Parameter name: type ---> System.FormatException: String was not recognized as a valid DateTime.<o:p></o:p>

       at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)<o:p></o:p>

       at System.Convert.ToDateTime(String value, IFormatProvider provider)<o:p></o:p>

       at System.String.System.IConvertible.ToDateTime(IFormatProvider provider)<o:p></o:p>

       at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)<o:p></o:p>

       at System.Web.Services.Protocols.ScalarFormatter.FromString(String value, Type type) <o:p></o:p>

    (if I send 8/30/2009 it response correctly). There both web.config globalization node are identical. Is it BUG in then framework, that don't consider on the culture ??? <o:p></o:p>



    Wednesday, September 2, 2009 9:56 AM

All replies

  • User799752452 posted

     Can anyone HELP ME ?  Cry

    Tuesday, September 8, 2009 6:07 AM
  • User-180320890 posted

    firstly check then your server date time is correct & use always system.datetime

    because this is better for datetime management

    if you use javasript then you use more better but a prob that js is not ssl language

    so system.datetime is better function for database management

    Tuesday, September 8, 2009 7:12 AM
  • User799752452 posted


    I try to define the param as system.datetime, but the problem was not resloved.

    The date time in the server is correct, - if the application running under framework 1.1 it is well and not exception occured.

    In the same server, if the same web service run under framework 2.0 (in another pool) I accept the Exception.Formatting

    Tuesday, September 8, 2009 2:22 PM