You can use the SoapFormatter just like the BinaryFormatter and it will work. The only thing you have to do is to add a reference of System.Runtime.Serialization.Formatters.Soap to get access to the Soapformatter(besides doing the same using the Imports keyword)
What is Serialization?
----------------------
Well, Serialization is the process of taking an object and converting it to a format
in which it can be transported across a network or persisted to a storage location. The storage location could be as simple as using a file or a database.
The serialized format contains the object's state information.
Deserialization is the process wherein you reconstruct an object from the serialized state to its original state. In essence, the process of serialization allows an object to be serialized, shipped across the network for remoting or persisted in a storage location such as the ASP.NET cache, and then be reconstructed for use at a later point in time.
There are three formats provided by the Microsoft .NET framework to which objects can be serialized. The formats are binary, SOAP, and XML. The XML format is produced by using the System.Xml.Serialization.XmlSerializer class. The SOAP and binary formats are produced by using classes under the System.Runtime.Serialization.Formatters namespace.
Here's the sample code you asked for. Hope this helps!
Sample code:
------------
Imports System.Runtime.Serialization.Formatters.Soap
Imports System.IO
Public Class Class1
Public Sub SoapSerialize()
'Create a streamreader class
Dim objStreamReader As StreamReader
'open the file
objStreamReader = File.OpenText("c:\\Mystore1.txt")
'Read the file storing it in the readfile string
Dim readfile As String = objStreamReader.ReadToEnd()
Dim flStream As FileStream = New FileStream("c:\\myStore.txt", FileMode.OpenOrCreate, FileAccess.Write)
Try
Dim sFormatter As SoapFormatter = New SoapFormatter
sFormatter.Serialize(flStream, readfile)
Finally
flStream.Close()
objStreamReader.Close()
End Try
End Sub
Cheers,
Monica
|