WCF 传输的序列化

// 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IService”。
[ServiceContract]
public interface IService
{

 [OperationContract]
 string GetData(int value);

 [OperationContract]
 CompositeType GetDataUsingDataContract(CompositeType composite);

 // TODO: 在此添加您的服务操作
}

// 使用下面示例中说明的数据约定将复合类型添加到服务操作。
[DataContract] //这句话就是在传输时候需要虚列化:自定义的类型因为其它的平台可能不认识,所以统一序列化变成可认识的数据
public class CompositeType
{
 bool boolValue = true;
 string stringValue = "Hello ";

    [DataMember]//这句话就是在传输时候需要虚列化:自定义的类型因为其它的平台可能不认识,所以统一序列化变成可认识的数据
 public bool BoolValue
 {
  get { return boolValue; }
  set { boolValue = value; }
 }

 [DataMember]
 public string StringValue
 {
  get { return stringValue; }
  set { stringValue = value; }
 }

原文地址:https://www.cnblogs.com/peter-peng/p/3452246.html