Process a large chunk of data in Web Service. Performance, Performance,Performance

Recently, I met a challenge to pass down a large chunk of data from a ASP.Net Server to Client. The data is structured as an object so serialization won't be a problem. But the data is about couple mb. What I did is to put this object into web response as attachment. The result is web service response time reduce half. I believe the reason behide this is that IIS might be doing some encoding/decoding that kill the performace.
This is what I did:
1: Install Microsoft WSE 2.0
2: When you finishe the web service process and before you return the response back, use the following code to return the response

System.IO.MemoryStream ms = new System.IO.MemoryStream();

System.IO.StreamWriter sw = new System.IO.StreamWriter(ms);

XmlSerializer serializer = null;

serializer = new XmlSerializer(typeof(MyObject), "http://MYObjectService/Service.asmx/20040803");

serializer.Serialize(sw, ret);

sw.Flush();

ms.Position = 0;

SoapContext respContext = ResponseSoapContext.Current;

DimeAttachment attachment = new DimeAttachment("text/plain",

TypeFormat.MediaType,

ms);

respContext.Attachments.Add(attachment);

serializer = null;

return "OK";

That will do it.

BTW: In order to extract the attachment at the client side, you need to install the WSE as well and use the response context object to extract the entire responese out.

posted on 2004-08-04 06:04  IAmInIT  阅读(679)  评论(0)    收藏  举报

导航