2011-04-07 80 views
4

我正在爲約會數據庫創建一個WCF數據服務。如何通過WCF數據服務公開TimeSpan?

我將約會存儲爲類型爲TimeSpan的持續時間的DateTime。當我試圖訪問我的數據服務,我得到以下錯誤:

"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."

任何想法,我怎麼能代表一個時間段,並把它通過訪問我的WCF數據服務?

回答

6

我會建議公開一個使用原始時間段的Ticks屬性的序列化新屬性(標記爲DataMemberAttribute)。

例如:

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

我不知道序列化的存取要求是什麼。也許你可以使用protected而不是public

0

您可以將持續時間暴露爲Ticks,TotalSeconds或其他可以計算爲小時,分鐘等的基元?