执行POST从Android的一个日期时间到WCF REST风格的JSON服务 [英] POSTing a DateTime from Android to a WCF RESTful JSON Service
问题描述
研究小时后,我还没有找到任何答案。 我试图发送一个DateTime作为参数传递给暴露了一个WCF RESTful服务使用JSON编码的一个方法。 请求是这样的:
after hours of research I still haven't found any answer. 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
- 在其发送的WCFTestClient应用过的net.tcp连带结果......
- 2010-07-01T10:54:00
- which is send by the WCFTestClient Application over net.tcp and it gets results...
在Methoddefinition:
The Methoddefinition:
LogEntry[] GetLogEntriesByModule( string module, DateTime lowerDate, DateTime upperDate, int maxEntries, out bool maxEntriesReached )
我总是以下响应:
I always the 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}
看来日期时间不正确地分析,因为有几个条目在日志中时间...
It seems the DateTime isn't correctly parsed, because there are several Entries in the Log for that Time...
有谁知道如何做到这一点?
Does anyone know on how to do this?
编辑:存在的问题是在服务器侧和已经解决
The Problem was on the server side and has been resolved.
推荐答案
有关使用发布日期WCF服务的正确的格式: /日期(532.44亿)/ 凡在barckets的数量是毫秒自1970年以来UTC午夜数。
The correct format for posting dates to WCF service is using : "/Date(53244000000)/" where the number in barckets 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+")/";
,然后用它作为以下
And then use it as below
inputparam.put("DateTime", datetime);
这将工作的肯定......请,如果您有任何问题,分享。
This will work for sure... Please share if you have any issues.
这篇关于执行POST从Android的一个日期时间到WCF REST风格的JSON服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!