当使用 WCF 处理 DateTime
对象时,返回的 DateTime
对象缺少 Kind
属性,它将始终是 DateTimeKind。 Unspecified
即使我在返回之前手动更改它!
我在 WCF 端这样做了:
dateFrom = DateTime.SpecifyKind(dateFrom , DateTimeKind.Utc);
仍然,它作为 DateTimeKind.Unspecified
发送给客户端...
客户端是 WinForm 应用程序,服务器是托管在 IIS 中的 WCF。
附言我知道 DateTime.ToUniversalTime()
方法,但这不是我需要的。
最佳答案
你可以在这个问题中找到解决方案:
Roundtrip XML Serialization of DateTime and xsd:date?
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. 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). So the information about kind is lost on serializing and deserializing.
关于c# - DateTime.Kind 未在 WCF 中返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14121343/