none
OData interoperability with odata4j and Edm.DateTime [System.FormatException: The string '2012-09-24T18:13' is not a valid AllXsd value] RRS feed

  • Question

  • Hi,

    i try to use a wcf client to consume a odata service which is provided by odata4j but without success. The Problem is, that sometime the client thows the following exception:

    System.FormatException: The string '2012-09-24T18:13' is not a valid AllXsd value

    After a short investigation it's seems that there is a problem with the usage of XmlConvert.ToDateTime in the WCF Data Service to parse  Edm.DateTime. XmlConvert.ToDateTime does't support allvalid Edm.DateTime representation which is described in the odata specification for the Atom Format. In my case the Problem occurs if the seconds part of the DateTime is zero, then the server sends the short form of the EDM.DateTime without seconds yyyy-mm-ddThh:mm.

    In the current odata specification you can found the following for Atom Format (http://www.odata.org/media/30002/OData%20Atom%20Format.html):

    Primitive Type:
    Edm.DateTime

    Represents date and time with values ranging from 12:00:00 midnight, January 1, 1753 A.D. through 11:59:59 P.M, December 9999 A.D.

    Literal Form
    yyyy "-" mm "-" dd "T" hh ":" mm [":" ss["." fffffff]]

    Example
    2000-12-12T12:00

    That means, that the server sends a valid date.

    It's a big problem for my application, actual i've patched the odata4j library to prevent the format without seconds but referred to to specification of odata, it's not a bug of odata4j.

    Patch for odata4j to avoid short Edm.DateTime form without seconds:

      public static String formatDateTimeForXml(LocalDateTime localDateTime) {
        if (localDateTime == null)
          return null;

        if (localDateTime.getMillisOfSecond() != 0)
          return localDateTime.toString(DATETIME_WITH_MILLIS_XML);
        //else if (localDateTime.getSecondOfMinute() != 0)
        return localDateTime.toString(DATETIME_WITH_SECONDS_XML);
        //else
        //  return localDateTime.toString(DATETIME_XML);
      }








    • Edited by hkiam Tuesday, September 25, 2012 6:11 AM
    Tuesday, September 25, 2012 5:28 AM

All replies

  • Hi hkiam,

    Welcome to MSDN Forum.

    I'm doing research on this issue now.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Friday, September 28, 2012 7:58 AM
    Moderator
  • Hi Allen Li,

    what's the state of your research, did you already have a result?

    Best Regards

    Thursday, October 25, 2012 12:01 AM
  • You need to write your own converter. Here's a similar issue: http://social.msdn.microsoft.com/Forums/eu/biztalkgeneral/thread/45b7e3f6-d12e-49b7-8d7f-23f36945c642
    Thursday, October 25, 2012 8:12 AM
  • Can someone from the WCF team respond?  Datetime values sans seconds are valid values according to the spec.

    Another one of our users hit this today: https://groups.google.com/d/topic/odata4j-discuss/MtAPBRcm6kY/discussion

    Verified that this is still an issue in the latest WCF DS version 5.1.0.  Looks like we'll have to put a workaround into odata4j since all WCF DS versions have this bug.

    <?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code /><m:message xml:lang="en-US">An error occurred while processing this request.</m:message><m:innererror><m:message>Cannot convert a primitive value to the expected type 'Edm.DateTime'. See the inner exception for more details.</m:message><m:type>Microsoft.Data.OData.ODataException</m:type><m:stacktrace>   at Microsoft.Data.OData.AtomValueUtils.ConvertStringToPrimitive(String text, IEdmPrimitiveTypeReference targetTypeReference)&#xD;
       at Microsoft.Data.OData.AtomValueUtils.ReadPrimitiveValue(XmlReader reader, IEdmPrimitiveTypeReference primitiveTypeReference)&#xD;
       at Microsoft.Data.OData.Atom.ODataAtomPropertyAndValueDeserializer.ReadPrimitiveValue(IEdmPrimitiveTypeReference actualValueTypeReference)&#xD;
       at Microsoft.Data.OData.Atom.ODataAtomPropertyAndValueDeserializer.ReadNonEntityValueImplementation(IEdmTypeReference expectedTypeReference, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, CollectionWithoutExpectedTypeValidator collectionValidator, Boolean validateNullValue, Boolean epmPresent)&#xD;
       at Microsoft.Data.OData.Atom.ODataAtomPropertyAndValueDeserializer.ReadProperty(String expectedPropertyName, IEdmTypeReference expectedPropertyTypeReference, ODataNullValueBehaviorKind nullValueReadBehaviorKind, Boolean epmPresent)&#xD;
       at Microsoft.Data.OData.Atom.ODataAtomPropertyAndValueDeserializer.ReadPropertiesImplementation(IEdmStructuredType structuredType, List`1 properties, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, Boolean epmPresent)&#xD;
       at Microsoft.Data.OData.Atom.ODataAtomPropertyAndValueDeserializer.ReadProperties(IEdmStructuredType structuredType, List`1 properties, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, Boolean epmPresent)&#xD;
       at Microsoft.Data.OData.Atom.ODataAtomEntryAndFeedDeserializer.ReadAtomContentElement(IODataAtomReaderEntryState entryState)&#xD;
       at Microsoft.Data.OData.Atom.ODataAtomEntryAndFeedDeserializer.ReadAtomElementInEntry(IODataAtomReaderEntryState entryState)&#xD;
       at Microsoft.Data.OData.Atom.ODataAtomEntryAndFeedDeserializer.ReadEntryContent(IODataAtomReaderEntryState entryState)&#xD;
       at Microsoft.Data.OData.Atom.ODataAtomReader.ReadAtEntryStartImplementation()&#xD;
       at Microsoft.Data.OData.ODataReaderCore.ReadImplementation()&#xD;
       at Microsoft.Data.OData.ODataReaderCore.ReadSynchronously()&#xD;
       at Microsoft.Data.OData.ODataReaderCore.InterceptException[T](Func`1 action)&#xD;
       at Microsoft.Data.OData.ODataReaderCore.Read()&#xD;
       at System.Data.Services.Serializers.EntityDeserializer.ReadEntry(ODataReader odataReader, SegmentInfo topLevelSegmentInfo)&#xD;
       at System.Data.Services.Serializers.EntityDeserializer.Read(SegmentInfo segmentInfo)&#xD;
       at System.Data.Services.Serializers.ODataMessageReaderDeserializer.Deserialize(SegmentInfo segmentInfo)</m:stacktrace><m:internalexception><m:message>The string '1959-03-02T00:00' is not a valid AllXsd value.</m:message><m:type>System.FormatException</m:type><m:stacktrace>   at System.Xml.Schema.XsdDateTime..ctor(String text, XsdDateTimeFlags kinds)&#xD;
       at System.Xml.XmlConvert.ToDateTime(String s, XmlDateTimeSerializationMode dateTimeOption)&#xD;
       at Microsoft.Data.OData.PlatformHelper.ConvertStringToDateTime(String text)&#xD;
       at Microsoft.Data.OData.AtomValueUtils.ConvertStringToPrimitive(String text, IEdmPrimitiveTypeReference targetTypeReference)</m:stacktrace></m:internalexception></m:innererror></m:error>



    • Edited by JohnSpurlock Sunday, November 11, 2012 3:47 PM Manually added hyperlink
    Sunday, November 11, 2012 3:47 PM
  • (ping)

    Can someone from the WCF team respond?

    Monday, November 19, 2012 2:46 PM
  • (bump)

    Earth to Microsoft.  Does anyone monitor these forums?

    Friday, November 30, 2012 2:56 PM
  • Hey John,

    I will bring this issue to the team and have a response by the end of the day. Sorry for the delay.

    Thanks,

    Chris Robinson - WCF Data Services Team


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Friday, November 30, 2012 4:46 PM
    Moderator
  • Hey John,

    We use existing functionality in the .Net Framework for parsing date time values.

    http://msdn.microsoft.com/en-us/library/system.xml.xmlconvert.aspx

    When we use this to do the parsing it throws an error in this situation when the seconds are not part of the string.

    It could be if we use these convert datetime function different we can convert the string in these situations.

    We will do some more investigation here, we are trying to stay away from rolling our own datetime parser when there is already one.

    Thanks,

    Chris Robinson - WCF Data Services Team


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Friday, November 30, 2012 5:20 PM
    Moderator
  • Looking at the product we specifically make the following call

    XmlConvert.ToDateTime(text, XmlDateTimeSerializationMode.RoundtripKind);

    Then it fails with part of the stack above.

    Thanks,

    Chris Robinson - WCF Data Services Team


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Friday, November 30, 2012 11:53 PM
    Moderator
  • Hi,

    Thanks a lot for sharing this. I also faced similar issue and able to solve this by the change suggested by you in odata4j.

    Regards,

    Viral Thakkar


    Viral

    Wednesday, December 5, 2012 8:08 AM
  • We have made a fix to our client so that it will understand this format. This fix will be in our upcoming 5.3 release.

    Thanks,

    Chris Robinson - WCF Data Services


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Friday, January 25, 2013 1:36 AM
    Moderator