WCF 中需要 datacontract 属性吗? [英] datacontract attribute is required in WCF?
问题描述
在 WCF 中是否需要 DataContract 属性?
is in WCF DataContract attribute is required?
我有一个类,该类没有用 DataContract 标记,也没有用 DataMember 标记属性.
I have a class that class is not marked with DataContract or property with DataMember.
当我在 4 个服务器上部署 wcf 服务时,out 4 个服务在 3 个服务器上运行良好,但在 1 个服务器上失败并显示消息类型'类'无法序列化.考虑使用 DataContractAttribute 属性对其进行标记,并标记其所有成员您想使用 DataMemberAttribute 属性进行序列化."
When i deploy wcf service on 4 server, out 4 service works fine on 3 server and failed on 1 server with message "Type 'Class' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute."
那么在 web.config 或 machine.config 或 IIS 中是否有任何设置可以强制我在代码中使用序列化程序?或
So is there any settings in web.config or machine.config or in IIS where i can mandate to use serializer in code? or
如果没有指定属性,我可以指定使用默认序列化程序吗?
i can specify to use default serializer if no attribute is specified ?
谢谢,克里希纳
推荐答案
不需要,DataContractAttribute 不是必需的 - WCF 将推断序列化规则.我唯一能想到的就是检查您所有服务器上的 .NET 版本是否相同.
No, the DataContractAttribute is not required - WCF will infer serialization rules. The only thing I can think of to check is that the version of .NET is the same on all of your servers.
更多信息:WCF 数据协定/序列化
这篇关于WCF 中需要 datacontract 属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!