Soap Formatter

Description :


We can create the soap formatted string and binary formaterd string by using the following string.

Name spaces

using System;
using System.IO;
using System.Collections;
using System.Runtime.Serialization.Formatters.Soap;
using System.Runtime.Serialization.Formatters.Binary;



Code Segments

class MainClass
{
private static void BinarySerialize(ArrayList list)
{
using (FileStream MyFileStream = File.Create("Mypeople.bin"))
{
BinaryFormatter MyBinaryFormatter = new BinaryFormatter();
MyBinaryFormatter.Serialize(MyFileStream, list);
}
}

private static ArrayList BinaryDeserialize()
{
ArrayList Mypeople = null;
using (FileStream MyFileStream = File.OpenRead("Mypeople.bin"))
{
BinaryFormatter bf = new BinaryFormatter();
Mypeople = (ArrayList)bf.Deserialize(MyFileStream);
}
return Mypeople;
}

private static void SoapSerialize(ArrayList list)
{
using (FileStream MyFileStream = File.Create("Mypeople.soap"))
{
SoapFormatter MySoapFormatter = new SoapFormatter();
MySoapFormatter.Serialize(MyFileStream, list);
}
}

private static ArrayList SoapDeserialize()
{
ArrayList Mypeople = null;
using (FileStream MyFileStream = File.OpenRead("Mypeople.soap"))
{
SoapFormatter MySoapFormatter = new SoapFormatter();
Mypeople = (ArrayList)sf.Deserialize(MyFileStream);
}
return Mypeople;
}
public static void Main()
{

ArrayList Mypeople = new ArrayList();
Mypeople.Add("A");
Mypeople.Add("B");
Mypeople.Add("C");
Mypeople.Add("D");


BinarySerialize(Mypeople);
SoapSerialize(Mypeople);

ArrayList binaryPeople = BinaryDeserialize();
ArrayList soapPeople = SoapDeserialize();

Console.WriteLine("Binary people:");
foreach (string Mystring in binaryPeople)
{
Console.WriteLine("\t" + Mystring);
}

Console.WriteLine("\nSOAP people:");
foreach (string Mystring in soapPeople)
{
Console.WriteLine("\t" + Mystring);
}
}
}



Code Explanation
1. Create an array list
2. Add the strings
3. Create the array list and store the Binary Deserialized data
4. Create the array list and store the soap Deserialized data
5. Disply the Binary string and soap string


By
Nathan


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: