【问题标题】:WCF datetime formatWCF 日期时间格式
【发布时间】:2015-08-21 05:15:14
【问题描述】:

我开发的 WCF 服务包含很多方法,这些方法返回 json 格式。我的主要问题是当我有数据合同成员的日期时间类型时,我在 json 中得到这样的 /Date(1233846970110-0500)/ 这导致我在 IOS 应用程序中出现问题。我如何编写一个转换为 MM/dd/yyyy 格式的全局方法以进行非常调用。我尝试了不同的方法,但是当我测试它时没有任何效果,总是返回相同的上述格式。

我在 global.ascx 中试过这样但喜欢

     private void RegisterRoutes()
    {
        // Create Json.Net formatter serializing DateTime using the ISO 8601 format
        var serializerSettings = new JsonSerializerSettings();
        serializerSettings.Converters.Add(new IsoDateTimeConverter());

        var config = HttpHostConfiguration.Create().Configuration;
        config.OperationHandlerFactory.Formatters.Clear();
        config.OperationHandlerFactory.Formatters.Insert(0, new JsonNetMediaTypeFormatter(serializerSettings));

        var httpServiceFactory = new HttpServiceHostFactory
        {
            OperationHandlerFactory = config.OperationHandlerFactory,
            MessageHandlerFactory = config.MessageHandlerFactory
        };

        RouteTable.Routes.Add(new ServiceRoute("VWPM_Srv", httpServiceFactory, typeof(IVWPM_Srv)));
    }

【问题讨论】:

    标签: ios wcf date-format


    【解决方案1】:

    如果你想发送一个 MM/dd/yyyy 格式的字符串。您只需将属性设为字符串并以 MM/dd/yyyy 格式分配日期。

    但是,您也可以让 ios 接受 wfc 发送给您的日期:

    json-serialized-date-passed-between-ios-and-wcf-and-vice-versa

    【讨论】:

      猜你喜欢
      • 2017-12-09
      • 1970-01-01
      • 1970-01-01
      • 2013-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多