反序列化SOAP响应空或无效的日期元素 [英] Deserializing SOAP-response with empty or invalid date element

查看:194
本文介绍了反序列化SOAP响应空或无效的日期元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我耗费了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:

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

  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.

有没有办法告诉.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.

推荐答案

有这个一个很好的谈话

<一个href="http://stackoverflow.com/questions/8084868/how-to-use-custom-serialization-or-deserialization-in-wcf-to-force-a-new-instanc">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";
  }
}

这篇关于反序列化SOAP响应空或无效的日期元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆