开发者

.NET WebService Sending Large XML File

开发者 https://www.devze.com 2022-12-13 18:18 出处:网络
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 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?


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


  • 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.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号