ASP.NET WebService: don't complain on a date format
One of the field in my web service method accepts DateTime value. Once service user provided value in wrong format: "31-10-2010" (or probably it was "31-10-10", to be honest: I not sure, are implementing logging right now). It is "dd-mm-yyyy" instead of "standard XML datetim开发者_开发技巧e been "yyyy-mm-ddTHH:MM:SS".
The problem that instead of rejecting such date as "wrong" (or invalid) web service successfully parsed this string as valid date, it was parsed as "31 of January, 2011 12:10 AM".
Question 1. Why the date is parsed at all?
Question 2. How to prevent that?
P.S. I've implemented business logic that check date to be in some meaningful range (no more then 10 years from now), but this don't help always...
XML has a well-defined format for dates and times. There is no excuse whatsoever for a client to send a date in a different format.
- If the date weren't parsed, then what would be passed to the service?
- I don't believe you. I have never seen an ASMX service have any sense of humor about date/time formats. Please post some code that reproduces the problem.
精彩评论