Mega Code Archive

 
Categories / C# by API / System Runtime Serialization Formatters Soap
 

New SoapFormatter()

using System; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Soap; [Serializable] class Customer {   private int CustomerNumber;   private string CustomerName;   private string CustomerCountry;   public void WriteCustomer()   {     Console.WriteLine("Customer Number: " + this.CustomerNumber);   }   public Customer(int newCustomerNumber, string newCustomerName, string newCustomerCountry)   {     this.CustomerNumber = newCustomerNumber;     this.CustomerName = newCustomerName;     this.CustomerCountry = newCustomerCountry;   } } public class MainClass {   public static void Main()    {     Customer MyCustomer = new Customer(1, "X Corporation", "France");     MyCustomer.WriteCustomer();     FileStream serializeStream = new FileStream("c:\\MyCustomer.xml", FileMode.Create);     SoapFormatter sf = new SoapFormatter();     sf.Serialize(serializeStream, MyCustomer);     serializeStream.Flush();     serializeStream.Close();     FileStream retrieveStream = new FileStream("c:\\MyCustomer.xml",FileMode.Open);     Customer NewCustomer = (Customer) sf.Deserialize(retrieveStream);     NewCustomer.WriteCustomer();   } }