POSTing a DateTime from Android to a WCF RESTful JSON Service

前端 未结 4 1216
醉话见心
醉话见心 2021-02-10 09:11

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 h         


        
4条回答
  •  [愿得一人]
    2021-02-10 09:37

    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

提交回复
热议问题