문제

I trying to pass a DateTime object as a query string parameter to a webservice method built with ServiceStack.net.

The date is properly URL encoded when passed but I keep getting the following error:

"Message":"KeyValueDataContractDeserializer: Error converting to type: String was not recognized as a valid DateTime.

Any ideas of how to correct this?

Here is an example of the URL encoded DateTime I was passing: 2%2f24%2f2012+5%3a13%3a02+PM

도움이 되었습니까?

해결책

If you have to pass datetimes as strings, try to pass them in an unambiguous format. I assume you're tying to pass the 24th February 2012, 17:13:02 - something like the following would be unambiguous:

2012-02-24T17:13:02

E.g. if you're formatting the date in .NET, use "o" or "s"


This is nothing to do with URL encoding - it's to do with passing data unambiguously - dates such as 01/02/2012 can be interpreted at least two ways - 1st February or 2nd January of this year, for two.

다른 팁

Have you looked at having the websservice accept a string parameter and then using DateTime.Parse or DateTime.TryParse to convert the string to a DateTime?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top