I encountered a problem with SOAP serialization and it would be great to find an answer. Here's a very simplified example:
public void Test()
{
    StringBuilder sb = new StringBuilder();
    StringWriter writer = new StringWriter(sb);
    SoapReflectionImporter importer = new SoapReflectionImporter();
    XmlTypeMapping map = importer.ImportTypeMapping(typeof(A));
    XmlSerializer serializer = new XmlSerializer(map);
    serializer.Serialize(writer, new A());
}
[Serializable]
public class A
{
    public A()
    {
        BB = new B();
    }
    public int a;
    public B BB;
}
[Serializable]
public class B
{
    public int A1 { get; set; }
    public int A2 { get; set; }
}
If I run method Test() then I get the following exception: System.InvalidOperationException: Token StartElement in state Epilog would result in an invalid XML document.
Would appreciate any help.