You just need to create a data class that can be serialized by both XMLSerializer and SOAPFormatter. This probably means that for XMLSerializer you will need an open class with public properties, and you will need to add the Serializable attribute for the SOAPFormatter. Otherwise, it is pretty straight forward.
I created an Naive example to illustrate what I mean:
[Serializable]
public class MyData
{
public int MyNumber { get; set; }
public string Name { get; set; }
}
class Program
{
static void Main(string[] args)
{
using (MemoryStream stream = new MemoryStream())
{
MyData data = new MyData() { MyNumber = 11, Name = "StackOverflow" };
XmlSerializer serializerXML = new XmlSerializer(data.GetType());
serializerXML.Serialize(stream, data);
stream.Seek(0, SeekOrigin.Begin);
data = (MyData)serializerXML.Deserialize(stream);
stream.Seek(0, SeekOrigin.Begin);
SoapFormatter serializerSoap = new SoapFormatter();
serializerSoap.Serialize(stream, data);
stream.Seek(0, SeekOrigin.Begin);
data = (MyData)serializerSoap.Deserialize(stream);
}
}
}
source
share