views:

279

answers:

2

I have a list of objects List that I need to send over a web service. The list contains about 37,000 Objects. This translates to about a 125 MB XML File if I serialized it to XML.

I think by default web services communicate via serialized XML. This leads me to believe I am actually sending 125MB file each time. In binary format this would only be about 5MB. Is there a way to make the Web Service call in binary format to avoid the large bandwidth hit?

+1  A: 
  • You could serialize to a binary array.
  • Then translate that array to a string.
  • Put that string in a structure, and send it over.
  • Then on the other side, convert the byte string array, back to a normal byte array.
  • Then re-serialize it into the object you need.
David Basarab
+2  A: 

Can you use WCF for your webservice? If so: WCF support streaming large data across the wire.

If you have any chance of compression that data on the server side to 5 MB in a ZIP or something, you could definitely stream that across to your client.

You would have something like this as your WCF service contract:

[ServiceContract(Namespace="http://yourservice.com/streaming/2009/12")]
interface IYourStreamingService
{
    [OperationContract]
    Stream GetListOfObjects(int id);
}

You can define methods that either take or return data as a "Stream", and the client can then open that stream like a FileStream or a MemoryStream, and the data will be streamed across the wire in chunks, so you won't need to allocate the whole data in memory before sending it to the client.

Marc

marc_s