Hi, I need to serialize class into soap xml stream.
When I do xmlSerializer.Serialize I could see following error "Token StartElement in state Epilog would result in an invalid XML document with Soap Serializer"
Here Is just a few simple code in order to reproduce this behaviour.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Serialization; namespace ConsoleApp1 { [SoapType(TypeName = "Child")] public class Child { public String ChildTag1 { get; set; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Serialization; namespace ConsoleApp1 { [SoapType(TypeName = "Master"), SoapInclude(typeof(Child))] public class Master { public String MasterTag1 { get; set; } public Child[] Childs { get; set; } } }
and finally xml soap serialization:
using System.IO; namespace ConsoleApp1 { class Program { static void Main(string[] args) { Master mas = new Master(); mas.MasterTag1 = "Tag1"; Child ch1 = new Child(); ch1.ChildTag1 = "Child1Tag1"; Child ch2 = new Child(); ch2.ChildTag1 = "Child2Tag1"; mas.Childs = new Child[] { ch1, ch2 }; MemoryStream target = new MemoryStream(); System.Xml.Serialization.XmlTypeMapping xmlTypeMapping = (new System.Xml.Serialization.SoapReflectionImporter().ImportTypeMapping(mas.GetType())); System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(xmlTypeMapping); xmlSerializer.Serialize(target, mas); byte[] result = target.ToArray(); } } }
When I comment out this line: publicChild[]Childs{get;set;} on master.cs class all works fine!
Could anyone help me to solve this issue?
Thanks
FabioBo