是DataContract属性必需的WCF [英] Is DataContract attributes required for WCF
问题描述
我写WCF服务,他的客户。我想发送/接收我的自定义类的对象,服务和客户端之间。
I'm writing WCF service and his client. I want to send/receive objects of my custom classes, between service and client.
我有3个模块
- WCF服务
- WCF客户端
- 在常见的类库
这两个WCF服务和客户端引用了共同的类库。 我不想以纪念我的所有类DataContract属性。
Both WCF service and client have references to common class library. I don't want to mark all my class with DataContract attributes.
所以,我的问题是必需的WCF DataContract属性?
So, my question "Is DataContract attributes required for WCF?"
我用.NET 4和NetTcpBinding的。
I use .NET 4 and netTcpBinding.
推荐答案
IIRC,如果你不使用正式的数据契约标记,则默认为像个场串器。这将工作,但不太容易的版本,因为私人的变化可以打破客户机/服务器。 IMO应始终正式装点WCF类型的数据合同/数据成员的属性。它会工作,没有他们,但错误的原因(IIRC,它最初的没有的没有正式标志的工作)。
IIRC, if you don't use formal data-contract markers, it defaults to acting like a field-serializer. This will work, but is less easy to version, since private changes can break the client/server. IMO you should always formally decorate WCF types with the data-contract/data-member attributes. It will work without them, but for the wrong reasons (IIRC, originally it didn't work without formal markers).
这篇关于是DataContract属性必需的WCF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!