[英]DateTime.Kind is not returned in WCF
When dealing with DateTime
objects with WCF, returned DateTime
objects are missing the Kind
property, it will always be DateTimeKind.Unspecified
even if I change it manually before returning it! 当使用WCF处理
DateTime
对象时,返回的DateTime
对象缺少Kind
属性,它将始终为DateTimeKind.Unspecified
即使我在返回之前手动对其进行了更改!
I did this in the WCF side: 我在WCF方面做到了:
dateFrom = DateTime.SpecifyKind(dateFrom , DateTimeKind.Utc);
still, it is sent as DateTimeKind.Unspecified
to the client... 仍然以
DateTimeKind.Unspecified
发送。未指定给客户端...
Client is WinForm application, server is WCF hosted in IIS. 客户端是WinForm应用程序,服务器是WCF托管在IIS中。
PS I am aware of the DateTime.ToUniversalTime()
method but that's not what I need. PS我知道
DateTime.ToUniversalTime()
方法,但这不是我所需要的。
You can find the solution in this question: 您可以在以下问题中找到解决方案:
Roundtrip XML Serialization of DateTime and xsd:date? DateTime和xsd:date的往返XML序列化?
There are different behaviors for handling Date, Time and DateTime values.
处理日期,时间和日期时间值有不同的行为。 For DateTime values, if XmlDateTimeSerializationMode is not Local the information about the kind (UTC, Local or Unspecified) is preserved.
对于DateTime值,如果XmlDateTimeSerializationMode不是Local,则保留有关类型(UTC,Local或Unspecified)的信息。 This is also true while deserializing.
反序列化时也是如此。 However, for Date and Time, they are always serialized out with the same format: (yyyy-MM-dd for Date and HH:mm:ss.fffffff.zzzzzz for Time).
但是,对于日期和时间,它们始终以相同的格式进行序列化:(对于日期,yyyy-MM-dd,对于时间,HH:mm:ss.fffffff.zzzzzz)。 So the information about kind is lost on serializing and deserializing.
因此,有关种类的信息会在序列化和反序列化时丢失。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.