反序列化SOAP响应空或无效的日期元素元素、日期、序列化、SOAP

2023-09-03 22:17:22 作者:Curtain 落幕

我耗费了SAP-NetWeaver的网络服务。响应对象包含一个数据,并且在未设置则返回0000-00-00。这导致了反序列化错误在我的.NET 4.0的WCF代理,因为用于.NET的最低有效日期将是0001-01-01。

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

我问SAP开发者来装饰用的minOccurs =0属性的日期元素,而忽略它,如果没有价值present但他说他不能这样做。

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.

在我要求他返回0001-01-01空日期 - 只为我的WCF代理 - 我想知道:

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

是0000-00-00的SOAP方面的有效日期?找不到它的任何SOAP规范,所以请让我知道你的信息来源。

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.

有没有办法告诉.NET解串器接受0000-00-00,处理像DateTime.MinValue?

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

非常感谢!

更新: 现在,SAP-web服务返回一个空的元素,如果日期为null。但我的问题是一样的。

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

推荐答案

有这个一个很好的谈话

here

也可以简单地实现定制去序列化的类。这样的0000-00-00的值会被逮住,并转化为DateTime.MinValue。 UPD:这是code我一直在谈论

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";
  }
}