Nested/inner classes in WCF?

北城余情 提交于 2019-12-11 08:37:37

问题


I would like to know if any problem exists after creating public nested/inner WCF classes (DataContracts). And if yes, what are theses problems.

(One of my colleague has seen some stuff on the Internet about such problems but they seem specific to some situation and we don't find a clear 'yes it will work' or 'no, nested classes don't work in WCF', therefore my guess is that they usually work.)


回答1:


Data Contracts form part of the public API your service exposes. Despite being represented in code by plain CLR classes (albeit decorated with an attribute) - do not be fooled - they are really serialized on the wire in to strings for consumption by the client/server. As such, from a service orientated view point, we must move away from the temptation to associated them to Object Orientated concepts.

Using Inheritance, Interface abstractions and nested classes all deal with OO concepts (polymorphism, abstraction and access), and even though some/all of these are technically possible in WCF (e.g. through the KnownTypes attribute) - just because you can do something - it doesn't mean you should.

I have no doubt there is some way to achieve the correct serialization behaviour to get WCF to recognize nested classes. However, in doing so I suspect you are going against the grain of service orientation - and consequently not using the full power of your service orientated architecture.



来源:https://stackoverflow.com/questions/19443838/nested-inner-classes-in-wcf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!