Use a derived type and attribute XmlInclude. For instance:
public class Book
{
public string Title;
public string Author;
}
public class MyBookType : Book { }
[XmlInclude(typeof(MyBookType))]
[XmlRoot("Books")]
public class Books : List<Book> { }
public void Run()
{
var b = new Books();
b.Add(new MyBookType
{
Title = "The Art of War",
Author = "Sun Tzu"
});
b.Add(new MyBookType
{
Title = "Great Expectations",
Author = "Charles Dickens"
});
var s = new XmlSerializer(typeof(Books));
s.Serialize(Console.Out, b);
}
Doing this produces this output:
<?xml version="1.0" encoding="IBM437"?>
<Books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Book xsi:type="MyBookType">
<Title>The Art of War</Title>
<Author>Sun Tzu</Author>
</Book>
<Book xsi:type="MyBookType">
<Title>Great Expectations</Title>
<Author>Charles Dickens</Author>
</Book>
</Books>
SOAP-, ASMX, , . [XmlInclude] , . , -.
XmlInclude, XSD WSDL, XSD, , #.
WSDL Books, Book. a MyBookType, , .