c# - DateTime.Kind 未在 WCF 中返回

标签 c# .net wcf datetime

当使用 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/

相关文章:

c# - 为什么 SonarQube Scanner for MSBuild 不适用于 MSBuild 15.0?

c# - ShowInTaskbar ="False"检测到Window被Win+D最小化

c# - WebAPI 2 OData - 没有 '~/entityset/key/$links/navigation' 的路由约定

wcf - 如何在 .NET 3.5 运行时的 Visual Studio 2010 SP1 中启动 WCF 服务主机?

c# - 在 Windows Phone 8.1 中使用什么进行 Paypal 付款

c# - 在 C# 中使用 linq 合并列表

c# - 将带有数组的 json 结构展平为多个没有数组的平面对象

c# - 我在什么情况下运行 C#?

c# - Convert.ToString(...) 或 Object.ToString() 提高性能

c# - 在 net.tcp wcf context 上传输用户信息