views:

16

answers:

1

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 datetime 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...

A: 

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.

  1. If the date weren't parsed, then what would be passed to the service?
  2. 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.
John Saunders
John, thanks for you answer. 1) if date is not parsed then "invalid request" error should be sent back or something like error message. 2) The code is on the "client" side, what I know about them is that their application works under UNIX. Probably they are thinking that send "31-10-2010"...
Budda
@Budda: it doesn't work that way. They are sending XML in SOAP format. They should be sending it according to the WSDL from the service. There is no excuse for them using any other format, as "UNIX format" is never used when sending data described in the WSDL as type `xs:date`. Feel free to post some UNIX code that reproduces the problem, or else reproduce it with .NET code and post that.
John Saunders
Don't have access to there code. Tried to reproduce... but don't know how to submit "own raw SOAP xml" for web-service...
Budda
I have no idea what you're going to do if you cannot reproduce the problem. You might try creating your own simple client program to show them how to do it. Otherwise, just tell them to send dates in the correct format.
John Saunders