Soap serialization works similarly to binary serialization. First, you need to add a reference to the System.Runtime.Serialization.Formatters.Soap.dll
assembly. Then you add an Imports System.Runtime.Serialization.Formatters.Soap
directive. At this point you can serialize and deserialize your objects. To continue the example of the typed collection shown in the previous section, write the following code to accomplish serialization with the Soap formatter:
Basically there is no difference in the syntax for the Soap formatter if compared to the binary one.
The SoapFormatter
class does not allow serializing generic collections. This is the reason why a simpler example against a single string is provided.
You can still examine the result of the serialization process with the Windows Notepad. Figure 43.2 shows how the target file stores information in a XML fashion.
Typically the Soap serialization is intended to be used when working with Soap web services. If you want to serialize objects in a pure XML mode, you can take advantage of Xml serialization, which is described in the “XML Serialization” section later in this chapter.
3.149.231.128