I have created an application to send data from WCF server application to my client side application. For this I have added a custom serialization instead of the default serialization. And now its sending data to the client as stream and I am able to de-serialize the object back in client application. But now my function only work for specific type. For instance if I am returning Class of type Customer its serializing and de-serializing based on the class I am specifying. I need to write a generic class which will accept any type of object for serialization and de-serialization. How can I do this?
Following is the piece of code that I want to generalize.
public class CustomBodyWriter : BodyWriter
{
private IEnumerable
- > Customers;
public CustomBodyWriter(IEnumerable
- > customers)
: base(false) // False should be passed here to avoid buffering the message
{
this.Customers = customers;
}
protected override void OnWriteBodyContents(System.Xml.XmlDictionaryWriter writer)
{
XmlSerializer serializer = new XmlSerializer(typeof(List
writer.WriteStartElement("Customers");
foreach (List
{
serializer.Serialize(writer, part);
}
writer.WriteEndElement();
}
}
public IEnumerable
- > GetAllCustomersImpl()
{
TestStreamingBL TestStreamingBL = new TestStreamingBL();
List
int count = 1;
foreach (Customer customer in TestStreamingBL.GetAllCustomers())
{
list.Add(customer);
if (count == 100)
{
count = 1;
yield return list;
list.Clear();
}
count++;
}
yield break;
}
In above code when ever the "yield return list" execute OnWriteBodyContents will get called
Any idea???
Anilal
VulpesPosted Mar 1, 2011, 6:37 AM
> serializableObjects;
> serializableObjects)