数据成员默认值,如何判断是否真的发送了某些内容?
默认情况下,WCF 将缺失的元素反序列化为默认值,例如 null、0 或 false。这种方法的问题在于,如果它是像数字 0 这样的基本类型,我不确定它是否意味着外部系统发送的实际值或 WCF 生成的默认值。
所以我的问题是:是否可以在运行时找出默认值是否意味着“我没有发送任何内容”。
这一点至关重要,因为我们不能仅仅因为外部系统这次没有发送特定元素(数据损坏)就用默认值更新和覆盖数据库中的现有数据。
微软的简短回答是“由接收端点来适当解释丢失的元素。”
数据成员默认值 http://msdn.microsoft.com/en-us/library/aa347792.aspx
有人可以澄清一下这是什么意思吗?
谢谢
By default, WCF deserializes missing elements into default values like null, 0 or false. The problem with this approach is that if it's a basic type like number 0 I'm not sure whether it means the real value sent by an external system or a default value generated by WCF.
So my question is: Is it possible to find out at run-time whether the default value means "I didn't send anything".
This is crucial because we can't update and overwrite existing data in the database with the default values just because the external system didn't send a particular element this time (data corruption).
Microsoft's short answer is "It is up to the receiving endpoint to appropriately interpret a missing element."
Data member default values
http://msdn.microsoft.com/en-us/library/aa347792.aspx
Can somebody please clarify what's that supposed to mean?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果将数据成员定义为属性,则可以使用是否调用 setter 来决定是否发送某些值。下面的代码显示了一个数据合约,它知道它是否反序列化了其字段。
If you define your data members as properties, you can use whether the setter was called or not to decide whether some value was sent. The code below shows one data contract which knows whether it deserialized its fields.