Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deserializing SOAP-response with empty or invalid date element

I am consuming a SAP-NetWeaver web-service. The response object contains a data and when it is not set it returns "0000-00-00". This leads to a deserialization error in my .NET 4.0 WCF proxy because the minimum valid date for .NET would be "0001-01-01".

I asked the SAP-developer to decorate the date element with the minoccurs="0" attribute and omit it if there's no value present but he states he can't do so.

Before I ask him to return "0001-01-01" for empty dates - just for my WCF proxy - I would like to know:

  1. Is "0000-00-00" a valid date in terms of SOAP? Couldn't find it in any SOAP specification so please let me know your source of information.

  2. Is there a way to tell the .NET deserializer to accept "0000-00-00" and handle it like DateTime.MinValue?

Many thanks!

UPDATE: Now the SAP-web-service returns an empty element if the date is null. But my problem remains the same.

like image 889
mono68 Avatar asked Jun 16 '26 00:06

mono68


1 Answers

there's a nice talk on this

here

it is possible to simply implement custom de serialisation of the class. so that the values of "0000-00-00" would be catched and converted into DateTime.MinValue. UPD: this is the code I've been talking about.

[OnDeserializing]
void OnDeserializing(StreamingContext c)
{
  if (MyCustonObj == null)
  {
    MyCustonObj = new MyCustomClass();
    MyCustonObj.MyStrData = "Overridden in  deserializing";
  }
}
like image 136
Igarioshka Avatar answered Jun 18 '26 21:06

Igarioshka