Don’t Forget: www.acehaid.org
Daily Archives: February 21, 2006
Boosting Windows Forms App Performance – yay!!!
I can barely contain my excitement over this article, “Practical Tips for Boosting the Performance of Windows Forms Apps” by Milena Salman in MSDN Mag (March 06). I read most of it this morning over breakfast and came down to my office with the sole intent of opening up the windows forms app I am getting ready to re-deploy in it’s shiny new .NET 2.0 makeover and finding any place that I can apply all of the awesome advice Milena dishes out in this article.
Of course, now it’s 2:00 and if I can just turn off Outlook, I.M. and the phone, I might actually get started on this.
Don’t Forget: www.acehaid.org
How I use XCeed streaming compression component to return web service data
I have mentioned my use of the XCeed streaming compression for returning data from web services a number of times in this blog. Here is a post when I first discovered that it reduced a 2.9 minute download of 4 MB to 12 seconds! I have since mentioned it a few times but never showed exactly how it is coded. Last night Rod Paddock pinged me to find out if I thought that component would work for him and it turned out he had the exact same scenario as I have been using it for. Therefore I showed him my code and thought I would put it here as well.
The key to all of this is that the component compresses bytes, so whatever you are returning, you want to convert it to bytes first. I’m sure this may make some web service purists cringe, but is it any different than returning a binary attachment with MTOM – which is a W3C standard? (I’m open to further education on this, my purist friends!)
Anyway, back to stream compression.
Let’s say you have a .NET client to .NET service scenario and are writing both ends. (That is a setup to avoid any rotten tomatoes for using a dataset in this example 🙂 ).
On the web service end, I have a method that accepts the dataset, converts it to a byte array, compresses that into another byte array using XCeed QuickCompression class and then returns this compressed byte array.
Using ms As New System.IO.MemoryStreamds.WriteXml(ms)
Dim bytearray(ms.Length) As Byte
bytearray = ms.GetBuffer
Dim CompressedBytes() As Byte
CompressedBytes = QuickCompression.Compress(bytearray, CompressionMethod.Deflated, CompressionLevel.Normal)
Return CompressedBytes
End Using
On the client end, having called this web service operation, I decompress the received bytes into a new byte array, then read that byte array into a new DataSet. Et Voila!
Dim ds As New DataSetDim compressedBytes() As Byte = WSProxy.GetDataSetasCompressedBytes
Dim byteArray() As Byte = QuickCompression.Decompress(compressedBytes)
Using ms As New MemoryStream
ms.Write(byteArray, 0, byteArray.Length)
ms.Position = 0
ds.ReadXml(ms)
End Using
I remember when I was first looking for a means of doing this and reading about this component, it wasn’t obvious how to do this in a web service, so I had a pointer from someone in tech support as to how to accomplish this.
I have used this combined with WSE 2.0 and now with WSE 3.0 to protect this data in addition to compressing it. If you have really humongous files, you can combine compression with MTOM in WSE 3.0 as well. I’ll have to check this out with WCF at some point.
Don’t Forget: www.acehaid.org