C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Serialization »

Soap Formatter


Posted Date: 20 Aug 2009    Resource Type: Code Snippets    Category: Serialization
Author: Shunmuganathan MMember Level: Diamond    
Rating: 1 out of 5Points: 10



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



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Soap Formatter  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Load / Save your objects with xml-Serialization
Previous Resource: NonSerializedAttribute in Serialization
Return to Discussion Resource Index
Post New Resource
Category: Serialization


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use