1.对System..Runtime.Serialization.Formatters.Soap.dll的引用。(经过我的试验,如果在VS.NET下需要添加,用csc编译不需要)
2.将using语句中的一个using System.Runtime.Serialization.Formatters.Binary改为using System.Runtime.Serialization.Formatters.Soap
3.将所有BinaryFormatter替换为SoapFormatter
4.将生成数据文件扩展名改为.xml
最后的控制台输出与前面例子的一样。
附上修改后的程序:
附上打开VS.NET中打开Insect.XML的截图: