Soap序列化反序列化

  public void Serialize(Book book)
        {
            using (FileStream fs = new FileStream(strFile, FileMode.Create))
            {
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(fs, book);
            }
        }

        public Book DeSerialize()
        {
            Book book;
            using (FileStream fs = new FileStream(strFile, FileMode.Open))
            {
                BinaryFormatter formatter = new BinaryFormatter(); [Page]
                book = (Book)formatter.Deserialize(fs);
            }
            return book;
        }

 

主要就是调用System.Runtime.Serialization.Formatters.Soap空间下的SoapFormatter类进行序列化和反序列化,使用之前需要应用System.Runtime.Serialization.Formatters.Soap.dll

 

除了标记为NonSerialized的其他所有成员都能序列化

 

 

SOAP序列化与二进制序列化的区别是:SOAP序列化不能序列化泛型类型

 

using System.Runtime.Serialization.Formatters.Soap;

 

 

 [Serializable]

你可能感兴趣的:(Soap序列化反序列化)