Hi
Your
Customers
-class is not serializable-friendly. And, unless you need some xml-formatting, not needed. And you set your
xmlFormatter.TargetTypes
to
typeof(Customers)
, while you are sending in an array of
Customer
.
I would have simply replaced Customers-class with a generic list
List<Customer>
.
You could also try serializing in your code to test how your list is serializing:
XmlSerializer s = new XmlSerializer(typeof(List<customer>));
List<customer> customerCollection = new List<customer>();
customerCollection.Add(new Customer(1,"Vishal", "Singla", 55423));
customerCollection.Add(new Customer(2,"Ashish", "Singla", 55422));
MemoryStream ms = new MemoryStream();
s.Serialize(ms, customerCollection);
ms.Position = 0;
StreamReader sr = new StreamReader(ms);
string serialized = sr.ReadToEnd();
sr.Close();
ms.Close(); </customer></customer></customer>
Results in:
<arrayofcustomer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<customer>
<customerid>1</customerid>
<customerfirstname>Vishal</customerfirstname>
<customerlastname>Singla</customerlastname>
<customerzipcode>55423</customerzipcode>
</customer>
<customer>
<customerid>2</customerid>
<customerfirstname>Ashish</customerfirstname>
<customerlastname>Singla</customerlastname>
<customerzipcode>55422</customerzipcode>
</customer>
</arrayofcustomer>
As you see, this serializes using
XmlSerializer
and also most probably using
XmlMessageFormatter
.