从Android发布DateTime到WCF RESTful JSON服务 [英] POSTing a DateTime from Android to a WCF RESTful JSON Service

查看:194
本文介绍了从Android发布DateTime到WCF RESTful JSON服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个 DateTime 作为参数发送到通过使用JSON编码的WCF RESTful服务公开的方法。请求如下所示:

I'm trying to send a DateTime as a parameter to a method exposed over a WCF RESTful service with JSON encoding. The request looks like this:

POST http://IP:PORT/LogService/json/GetLogEntriesByModule HTTP/1.1
Content-Length: 100
Content-Type: application/json
Host: IP:PORT
Connection: Keep-Alive
User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4)
Expect: 100-Continue

{"maxentries":10,"upperdate":"1280703601462","lowerdate":"1277938801462","module":"Windows Service"}



< :

I tried several formats for the DateTime:


  • 2010-07-01T10:54:00 (由...发送通过NET.TCP的 WCFTestClient 应用程序,并获得结果

  • \ / Date(12345678 + 0100) \ /

  • 01.07.2010 10:54:00

  • 2010-07-01T10:54:00 (which is send by the WCFTestClient application over NET.TCP and it gets results
  • \/Date(12345678+0100)\/
  • 01.07.2010 10:54:00

方法定义:

LogEntry[] GetLogEntriesByModule(
    string module,
    DateTime lowerDate,
    DateTime upperDate,
    int maxEntries,
    out bool maxEntriesReached
)

我总是得到以下回复: p>

I always get the following response:

HTTP/1.1 200 OK
Content-Length: 60
Content-Type: application/json; charset=utf-8
Server: Microsoft-HTTPAPI/2.0
Date: Fri, 02 Jul 2010 09:07:04 GMT

{"GetLogEntriesByModuleResult":[],"maxEntriesReached":false}

似乎 DateTime 没有正确解析,因为当时的Llog中有几个条目。

It seems the DateTime isn't correctly parsed, because there are several entries in the Llog for that time.

有谁知道如何做到这一点?

Does anyone know on how to do this?

更新:问题出在服务器端,已解决。

Update: The problem was on the server side and has been resolved.

推荐答案

发布日期到WCF服务的正确格式是:
/ Date(53244000000)/
其中括号中的数字是自1970年UTC午夜以来的毫秒数。

The correct format for posting dates to WCF service is using: /Date(53244000000)/ where the number in brackets is the number of milliseconds since 1970 UTC Midnight.

Date dt = new Date();
long date = Date.UTC(dt.getYear(), dt.getMonth(), dt.getDay(), dt.getHours(),dt.getMinutes(), dt.getSeconds());
String senddate = "/date("+date+")/";

然后使用它如下

inputparam.put("DateTime", datetime);

这篇关于从Android发布DateTime到WCF RESTful JSON服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆