Complete-Reference-Vb Net 75
Complete-Reference-Vb Net 75
However, to instantiate SoapFormatter as meData, we need to reference the SoapFormatter class. This
should be done using an Imports directive as follows:
Imports System.Runtime.Serialization.Formatters.Soap
Next it would be a good idea to create the stream and file support for our object or it will be going nowhere in
a hurry. This is achieved using the following code:
If File.Exists(target) Then
File.Delete(target)
ElseIf (Not File.Exists(target)) Then
Dim fileForObject As New FileStream(target, IO.FileMode.Create)
...
So, what have we done here so far? In the SerializeOut method, we created a SoapFormatting object that
provides the necessary transport to move the data from the object's location in memory to storage. We could
have used TCP or some other transport mechanism, but SOAP is an excellent protocol to use and allows us to
support the serialization of the object across machine and even process boundaries.
Notice the target parameter in the PlayOutList signature. This variable gives us a unique string containing
path and filename as the target that will receive the current object to be serialized.
Finally, we call the Serialize method on the FileStream object and reference the current object's data via the
Me keyword. Here's the code that achieves this:
meData.Serialize(fileForObject, Me)
fileForObject.Close()
To recap: first, we created a new file to receive the SOAP stream. Then, we called the Serialize method on
Me and bridged it to the target file. After the job is done, it is a good idea to close down the FileStream
object with a simple call to its Close method. You can check the serialized data in the file. If everything
worked according to plan, the saved file will contain data that looks like this (very much abridged with the
data
in the linked list shown in bold):
<SOAP−ENV:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema−instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP−ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP−ENV="http://schemas.xmlsoap.org/soap/envelope/"
SOAP−ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
...
</SOAP−ENV:Body>
</SOAP−ENV:Envelope>
559