views:

52

answers:

1

Hi, 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
    • which is send by the WCFTestClient Application over net.tcp and it gets results...
  • \/Date(12345678+0100)\/
  • 01.07.2010 10:54:00

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?

EDIT: The Problem was on the server side and has been resolved.

A: 

Just in case this helps somebody:

According to Microsoft, WCF uses a QueryStringConverter to do the url parsing. Thus, using this code (slight modification of the msdn example):

QueryStringConverter converter = new QueryStringConverter();
if (converter.CanConvert(typeof(DateTime)))
{
    string strValue = converter.ConvertValueToString(DateTime.UtcNow, typeof(DateTime));
    Console.WriteLine("the value = {0}", strValue);
}

we get the proper format for DateTime REST parameters: 2010-01-01T01:01:01Z

I did read that you tried this format, but just wanted to confirm that this is indeed the way it's supposed to work. I thought of answering since this question came up first when I searched for this.

This worked for me using .NET 4.0

esegura