在WCF通信过程中,它支持三种类型的序列化机制:XmlSerializer, DataContractSerializer, and NetDataContractSerializer. 默认下,如果我们不为需要进行序列化的类添加标记,它会以XmlSerializer这种机制来序列化数据(注意:需要将该类定义为public,否则会出现以下类似异常:
Type 'WCFService.UserDataContract' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.。)此时,类中所有公有的字段和属性都将进行序列化。
Type 'WCFService.UserDataContract' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.。)此时,类中所有公有的字段和属性都将进行序列化。
当然,在WCF架构中,在数据的序列化时我们应尽量使用DataContractSerializer这种机制。它对于数据的自定义提供更强大的支持
引自:http://www.cnblogs.com/wcfgroup/archive/2008/06/03/1213119.html