DateTime format error in XML SOAP Response from web service RRS feed

  • Question

  • There is an error in XML document (4, 294). ---> System.FormatException: String was not recognized as a valid DateTime

    I'm getting an XML DateTime exception on my C# web app client when I call a web service that was auto-generated using Visual Studio web references. The error occurs at the web service client endpoint as the web reference proxy is formatting the XML response. Because of the type of error, I'm think it has to do with RequestTimeStamp or ResponseTimeStamp elements within the XML response. I'm wondering if there is a .NET bug or incompatibility with converting certain Text formats to DateTimes formats. What's a good way to trace the cause of this error and to look at the XML response- I couldn't find a way in Visual Studio 2003 to examine the XML response from the Web Service.

    Heres the exception details:
    System.InvalidOperationException: There is an error in XML document (4, 294). ---> System.FormatException: String was not recognized as a valid DateTime.
       at System.DateTimeParse.ParseExactMultiple(String s, String[] formats, DateTimeFormatInfo dtfi, DateTimeStyles style, DateTime& result)
       at System.DateTime.ParseExact(String s, String[] formats, IFormatProvider provider, DateTimeStyles style)
       at System.Xml.XmlConvert.ToDateTime(String s, String[] formats)
       at System.Xml.Serialization.XmlCustomFormatter.ToDateTime(String value, String[] formats)
       at System.Xml.Serialization.XmlCustomFormatter.ToDateTime(String value)
       at System.Xml.Serialization.XmlSerializationReader.ToDateTime(String value)
       at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read3_OnDemandMeterPingResponseType(Boolean isNullable, Boolean checkType)
       at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read9_requestMeterStatusSyncResponse()
       --- End of inner exception stack trace ---
       at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
       at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, XmlDeserializationEvents events)
       at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader)
       at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
       at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
       at EAIInterface.MeterPingService.OnDemandMeterPingService.requestMeterStatusSync(OnDemandMeterPingRequestType onDemandMeterPingRequest) in C:\DATA\Website\Practice\EAIInterface\Web References\MeterPingService\Reference.cs:line 42
       at EAIInterface.EAI.GetMeter(String SPID, String UID) in c:\data\website\practice\eaiinterface\eai.cs:line 766

    Date time XML sample from Web Service host:

    Wednesday, March 7, 2007 1:59 AM

All replies

  • Both your sample DateTime values seems to work just fine. If you could give the DateTime value that doesn’t works, we could try to further check on them. 

    You can try to use the WebServiceStudio from http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=65a1d4ea-0f7a-41bd-8494-e916ebc4159c and check the xml messages.

    Wednesday, March 7, 2007 9:50 PM
  • Yea, I have a feeling that DataTime data from the response is bad. I requested the response data values from the web service group since I can't find a way to check the messages.

    The WebServiceStudio is a neat tool for this but unfortunately it cannot let me populate the headers. Are there similar tools that is more robust?

    Thursday, March 8, 2007 1:34 AM
  • I found the error is due to an empty responseDateTime field being returned. Is there a way to set my client to remove any elements with a null DateTime value type in the response so that it does not error out?

    Wednesday, March 14, 2007 11:05 PM
  • Hi Traderhen,


    Did you find any solution to your problem on how remove any elements with a null DateTime value type?





    Wednesday, January 2, 2008 7:18 PM
  • Does anyone have a solution to this now? Im a getting a very similar problem to the described above.

    My SOAP-response is fine when getting it over soapUI, but if i want to do it over my wsdl generated c# code the DateTime cannot be parsed in a proper way automatically. This means that i am getting the following InnerException:

    {"String was not recognized as a valid DateTime."}

    The datetime format is like this in the soap-response: "2010-06-15T16:50:45".

    Bacause its all autogenerated code i´ve got no influence on the deserialization process.



    Monday, May 2, 2011 10:41 AM
  • I believe that needs to end with a "Z" or with a time zone.


    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects
    Monday, May 2, 2011 2:01 PM
  • Hi John,

    thank you for your response. I took a simple project from the web where i could test this behaviour.

    Though, the difference is the source: XML-File vs.SOAP-response.

    Anyways i tried it with the XML de- and serialization. After serialization to the XML file i have got the following DateTime-Format like you said:




    Deserialization works fine. But it works fine as well with this format




    Is there any special difference between XML-Deserialization and the one for SOAP-responses generated by wsdl? Hmm, i think i have to check the details with the Reflector.



    Tuesday, May 3, 2011 8:57 AM
  • No, the two are identical.

    John Saunders
    WCF is Web Services. They are not two separate things.
    Use WCF for All New Web Service Development, instead of legacy ASMX or obsolete WSE
    Use File->New Project to create Web Service Projects
    Tuesday, May 3, 2011 4:16 PM
  • Hi a.pawi,

    Did you find any solution now? I'm  getting a very similar problem. I call a php webservice from .net. My SOAP-response is fine in soapUI, but in Visual Studio I have the same problem.



    Wednesday, September 7, 2011 1:47 PM
  • This is issue with the culture. You might be sending datetime from client in different culture. At web service end, the culture is different.

    When you pass it, supply InvariantCulture. While accessing parse it using InvariantCulture.

    Hope this helps.

    Pravin Arote, MCTS - Web Technologies If reply answers your question, Please mark as Answer :)
    Friday, September 9, 2011 6:32 AM