OData与odata4j和Edm.DateTime的互操作性[System.FormatException:字符串'2012-09-24T18:13'不是有效的AllXsd值] [英] OData interoperability with odata4j and Edm.DateTime [System.FormatException: The string '2012-09-24T18:13' is not a valid AllXsd value]

查看:66
本文介绍了OData与odata4j和Edm.DateTime的互操作性[System.FormatException:字符串'2012-09-24T18:13'不是有效的AllXsd值]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用wcf客户端来使用odata4j提供的odata服务,但没有成功。问题是,有时客户端会抛出以下异常:

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:字符串'2012-09-24T18:13'不是有效的AllXsd值

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

经过短暂调查后,似乎在WCF数据服务中使用XmlConvert.ToDateTime来解析Edm.DateTime时出现问题。  XmlConvert.ToDateTime不支持所有有效的Edm.DateTime在atom格式的odata规范中描述
的表示。在我的情况下,如果DateTime的秒部分为零,则会出现问题,然后服务器发送EDM.DateTime的缩写形式,而不是秒yyyy-mm-ddThh:mm。

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.

在当前的odata规范中,您可以找到以下Atom格式(http://www.odata.org/media/30002/OData%20Atom%20Format.html):

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

原语类型:

Edm.DateTime

Primitive Type:
Edm.DateTime

表示日期和时间,其值范围为午夜12:00:00,公元1753年1月1日至公元9999年12月9日下午11:59:59

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]]

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

示例

2000-12-12T12:00

Example
2000-12-12T12:00

这意味着,服务器发送有效date。

这对我的应用程序来说是一个大问题,实际上我修了odata4j库可以防止没有秒的格式,但是提到了odata的规范,它不是odata4j的错误。

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.

修补odata4j以避免短时间内没有秒的Edm.DateTime形式:

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




推荐答案

嗨hkiam,

Hi hkiam,

欢迎来到MSDN论坛。

Welcome to MSDN Forum.

我正在研究这个问题。

最诚挚的问候


这篇关于OData与odata4j和Edm.DateTime的互操作性[System.FormatException:字符串'2012-09-24T18:13'不是有效的AllXsd值]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆