Banshee
Banshee

Reputation: 15807

WCF and Datetime parsing?

I got a WCF service(Webservice HTTP) that contains a service method, this method takes a datacontract containing a DateTime? (nullable).

There is now reports of exceptions when the client sends a string like this to this DateTime field

"2018-04-00T00:00:00"

I understand that this is not a correct datetime but accoding to the BizTalk user this is a webservice standard?

So how should I handle this with WCF?

Upvotes: 2

Views: 1383

Answers (2)

tom redfern
tom redfern

Reputation: 31750

I can see how this is kind of grey area, but the fact is that the serializer cannot handle the data being sent. The serializer is your first line of defense against bad data in messages, and the only way (unless you have 500 lines of validating code) of catching all possible permutations of bad data. What if tomorrow they decide to send you a date like "2018-78-45T00:00:00"?

To me this means the burden of change is on the callers side. Full stop. The problem is not that they are sending data which is badly formatted, but that they are sending data which is just plain bad.

If they cannot provide correctly populated date values then returning an exception back to them with that information in is a completely reasonable solution.

Upvotes: 0

daryal
daryal

Reputation: 14919

WCf uses this DateTime xml schema. And according to schema, the format seems valid, but since the third argument (00) represents the day and proper day parameters start from 01, it fails.

Upvotes: 1

Related Questions