我如何公开通过WCF数据服务的时间跨度?跨度、时间、数据、WCF

由网友(空巷)分享简介:我为我的约会数据库中创建一个WCF数据服务。I am creating a WCF Data Service for my database of appointments.我存储被任命为同类型的时间跨度的持续时间的日期时间。当我试图访问我的数据服务,我得到以下错误:I'm storing the appoint...

我为我的约会数据库中创建一个WCF数据服务。

I am creating a WCF Data Service for my database of appointments.

我存储被任命为同类型的时间跨度的持续时间的日期时间。当我试图访问我的数据服务,我得到以下错误:

I'm storing the appointment as a DateTime with a duration of type TimeSpan. When I attempt to access my data service, I get the following error:

服务器遇到一个错误处理请求的异常消息是在类型'任命'的类型是'时间',这是不支持的基本类型。'属性'持续时间。详情参见服务器日志。

"The server encountered an error processing the request. The exception message is 'The property 'Duration' on type 'Appointment' is of type 'Time' which is not a supported primitive type.'. See server logs for more details."

任何想法如何,我可以重新present的持续时间,并把它通过我的WCF数据服务访问?

Any idea how I can represent a time duration and have it accessible through my WCF Data Service?

推荐答案

我会建议暴露了序列化一个新的属性(标有 DataMemberAttribute )使用蜱属性。

I would suggest exposing a new property for serialization (marked with the DataMemberAttribute) that use the Ticks property of your original timespan.

例如:

[DataMember("TheTimeSpanTicks")]
public long TheTimeSpanTicks
{
    get { return TheTimeSpan.Ticks; }
    set { TheTimeSpan = new TimeSpan(value); }
} 

我不知道什么序列化的访问要求会。也许你可以使用保护而不是公开

阅读全文

相关推荐

最新文章