开发者

How to intercept WCF JSON parsing for a post request

I have a WCF web service which uses JSON format, my problem is with the date fields, when I try to post a date to my service I can't find any other format other than the "/Date(53244000000)/" where the number is the number of milliseconds since 1970 midnight.

My Project manager is not accepting with this format, and he wants me to be able to post the dates to my service using the ISO-8601 format, or any other readable format.

I have searched a lot and I didn't find any other format to post to the service with, so I have thought in Intercepting the WCF JSON parsing and parse the date (I don't开发者_开发百科 know if that's possible or not).

So, any suggestion to get over this date problem ?


use a string property for your json datacontract and do the ISO-8601 parsing in the implementation as a validation.

public class MyService
{

  public void MyDate(string isodate)
  {
     DateTime realdate;
     if (!DateTime.TryParseExact(isodate, 
          "YYYY-MM-DD", 
          new CultureInfo("en-US"),
          DateTimeStyle.None, 
          out realdate))
     {
        throw new ArgumentException("not in correct format", "isodate");
     }

  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜