嵌套/内部类在​​WCF? [英] Nested/inner classes in WCF?

查看:145
本文介绍了嵌套/内部类在​​WCF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在创建公共嵌套/内部WCF类(DataContracts)之后是否存在任何问题。如果是的话,这些问题是什么。

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

(我的一个同事在互联网上看到一些关于这些问题的东西,但它们似乎具体到某些情况,找到一个明确的是的将工作或不,嵌套类不工作在WCF,因此我的猜测是,他们通常工作。)

(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.)

推荐答案

数据合同是您的服务公开的公共API的一部分。尽管在代码中用简单的CLR类来表示(虽然用属性来装饰) - 不要被欺骗 - 它们真正地串行化到字符串中以供客户端/服务器使用。因此,从面向服务的角度来看,我们必须远离诱惑,将它们关联到面向对象的概念。

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.

使用继承,接口抽象和嵌套类与OO概念(多态,抽象和访问),并且即使一些/所有这些在WCF中在技术上是可能的(例如通过 KnownTypes 属性) - 只是因为可以做某事 - 这并不意味着你应该。

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.

我毫不怀疑,有一些方法来实现正确的序列化行为,让WCF识别嵌套类。但是,在这样做的时候,我怀疑你会违背服务导向的格局 - 因此不能使用面向服务架构的全部功能。

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.

这篇关于嵌套/内部类在​​WCF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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