Keep your Silverlight app running fast by compressing your service responses. Imagine you’re downloading 1MB worth of text. Compressed, that same text can usually be reduced to under 200K. This reduction can be significant enough to be noticable to even clients on good internet connections and over time will save you money on bandwidth usage.
Fortunately, there’s NO need to find a 3rd party zip component or to try to do it yourself. IIS has everything all built right in, you just need to enable it.
The way it works is, the browser sends up an http header of “Accept-Encoding” with gzip and/or deflate as the value with each request to your WCF service. As long as IIS is configured correctly, the server will automatically compress the response from the service and the client will automatically decompress it before your code enters the picture. Not a single line of code is required on our part to take full advantage of this built in compression feature that works across most major browsers.
To set up IIS6 to participate you need to (sorry, haven’t tried this on IIS7):
1) In the IIS console, right click on “Web Sites”, choose properties, select the Services tab and check “Compress application files”
2) Also in the IIS console, go to the Web Service Extensions folder and click the “Add a new Web service extension” link. In the dialog that appears, enter a name for the extension. I named mine “gzip”. Next, enter the path of the dll capable of zipping the responses (c:\windows\system32\inetsrv\gzip.dll), and check “Set extension status to Allowed”.
3) Run the following command lines to update metabase.xml:
CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/GZIP/HcScriptFileExtensions “asp” “dll” “exe” “svc”
CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/DEFLATE/HcScriptFileExtensions “asp” “dll” “exe” “svc”
CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/GZIP/HcDynamicCompressionLevel 9
CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/DEFLATE/HcDynamicCompressionLevel 9
4) Restart IIS (you can right click on the computer name in the IIS console, choose All Tasks, and select “Restart IIS”). Not 100% sure this is necessary.
5) Wait. It took my server on Amazon EC2 approximately 3 minutes before the changes from step #2 flowed to the metabase.xml file. You can always go check by looking at the date modified of c:\windows\system32\inetsrv\metabase.xml
In the end, you can test that it’s working by going to PipeBoost and typing in the url of your .svc file. Also, when running your app, you can use a tool like fiddler2 to show you the data actually coming down to the client along with an indicator that it is compressed.
That’s it, don’t do a think to your Silverlight app but watch it instantenously start downloading data faster!
This is terrific. I was looking for such solution for a while
Thyank you very much
[…] more on programmerpayback.com […]
[…] Speeding Up Your Website: Optimizing GIFs images | yensdesign … […]
Hy,
It’s seems to me that this an optimal solution,
but my problem is i don’t understand the settings like:
W3Svc/Filters/Compression/GZIP/HcScriptFileExtensions “asp” “dll” “exe” “svc”
or
CSCRIPT.EXE ADSUTIL.VBS SET W3Svc/Filters/Compression/GZIP/HcDynamicCompressionLevel 9
what does this means and what other options we have for it in what cases ?
It will be nice to have a link or an article for that 🙂
And i have another question:
On the 2 Section (Add Web Service Extensions) We could put a custom .dll? For example if i write a super fancy zipper could i use it?
And it’s needs to be classic dll or .net dll ??
Please answer these questions
Zoli, good questions. When you check “Compress application files” in IIS, it only sets .asp, .dll, and .exe files to have their results are compressed. However, we of course also want .svc files to be included in the mix so calling that did the trick. You could add additional file extensions to it like “cfm” for ColdFusion…etc. The compression level is merely the level of compression you want to use. 9 is the highest I believe. You could use a lower number to create faster compression and decompression but with the trade off of having lower compression ratios. This is up to you. I would recommend the higher number if your calls are chunky and lower numbers if your service calls are real chatty. It’s too bad this can’t be controlled on a per page level. 😦
Regarding your 2nd question, I don’t know the answer to your Q but my guess is that you could use a custom dll here as long as you adhered to the proper API. I’d also guess that this is not a .NET dll but rather, the good old fashioned kind.
Tim, good post – IIS compression is something that we have been using to help speed up SharePoints big .js and .css files for a while.
I would however be concerned with my design if my WCF service requests were returning 1MB responses? At this point I would want to be looking at an alternative such as MTOM (http://blogs.msdn.com/jevdemon/archive/2005/05/05/415126.aspx)
Andrew your link is not working.
For me on local it’s not working,i tryed to reset the IIS, or stopping the WCF site.
but i will see the related posts maybe there i will found a solution.
Oh i forgot those who are trying this solution:
ON the section 3:
you need to search for CSCRIPT.exe
(C$\windows\system32\CSCRIPT.exe)
and you need to copy the adsutil.vbs here because they are not in the same directory so this command script will crash.
Maybe i helped somebody 🙂
[…] Acording Although encoded xml can be compressed at a slightly higher compression ratio, it was not as dramatic as I thought and suggests and the final compressed sizes show that although compression on the server helps reduce the size of your response a great deal, xml encoded strings will still be larger than necessary. Check out my previous blog post to find out more about opimizing responses by turning on server compression. […]
Hi, Tim.
Is it possible to configure IIS 7 to use compression in WCF responses? If so, how do you do that?
Thanks a lot,i was looking for this exact solution
For IIS7 http://blog.wassupy.com/2009/08/enabling-dynamic-http-compression-in.html
To WCF binary use
1. install “dynamic file compression” IIS feature as above
2. In ApplicationHost.config add to dynamic types
3. “enable dynamic content compression” in your IIS compression setting.
As for instance, we have a report that 5000 lines 5mb takes 23. 1 seconds but we compression enabled in IIS7 it compreses to 299kb with 3.3 seconds
Tag issue in response above for 2 it should read
2. In ApplicationHost.config add to dynamic types <add mimeType=”application/soap+msbin1″ enabled=”true” /> to dynamictypes
Thanks for the handy article. Two “gotchas” I ran into implementing this.
I had fiddler open testing silverlight hitting the SVC (all hosted externally). I saw no compression at all. Tried the same thing from my home PC: 750k of XML went down to 18k – nice! I checked the IIS logs, all requests coming via my work proxy are serving up 750k. So corporate proxies can get in the way of this. 😦
Second (which may not be IMMEDIATELY obvious) data going from silverlight to a WCF service won’t be compressed.
Yes, I was expecting iis compression after applying the scripts, but not luck at all. If I access the wcf service say WCFTest1.svc in browser then it will compress it, and if accessed from Silverlight application then no compression.
[…] Source http://programmerpayback.com […]
Hi,
We are using Silverlight 4.0 with WCF for Dot Net 4.0 with iis 6.
And our content type for response is application/soap+msbin1.
In iis 7, i have successfully enabled compression by adding application/soap+msbin1 to httpcompression, but not luck in iis 6.
my question is how can i enable dynamic compression this for iis 6 for content type application/soap+msbin1?
Thanks
Hi,
After playing about one week and even implementing custom compression i found that we have to enable AspNetCompatibility Mode for wcf for iis 6 but it works fine without it too in iis 7. Please follow the link for more details:
http://www.traviswhidden.com/PublicBlog/tabid/358/EntryId/420/asp-net-and-wcf-compression-via-IIS.aspx
Thanks
I think it’s worth while to mention that you can not just copy and paste the lines at point 3. The compression for svc won’t work.
You have to remove the “ around the extensions.
Wow that was unusual. I just wrote an incredibly long comment but after I clicked submit my
comment didn’t appear. Grrrr… well I’m not writing all that over again.
Anyhow, just wanted to say wonderful blog!
I loved as much as you will receive carried out right here.
The sketch is attractive, your authored subject matter stylish.
nonetheless, you command get got an edginess over that you wish be
delivering the following. unwell unquestionably come more formerly
again since exactly the same nearly very
often inside case you shield this hike.
Hey I know this is off topic but I was wondering if
you knew of any widgets I could add to my blog that automatically tweet
my newest twitter updates. I’ve been looking for a plug-in like this for quite
some time and was hoping maybe you would have some experience with something like this.
Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new
updates.
Hi there, just wanted to mention, I liked this article. It was helpful.
Keep on posting!
Greetings from Florida! I’m bored at work so I decided to
browse your blog on my iphone during lunch break.
I enjoy the info you present here and can’t wait to take a look when I get home.
I’m surprised at how fast your blog loaded on my cell phone ..
I’m not even using WIFI, just 3G .. Anyhow, wonderful site!
I have read a few just right stuff here. Certainly worth bookmarking for revisiting.
I surprise how a lot effort you place to make
one of these fantastic informative website.
It’s actually a nice and useful piece of info. I’m glad that
you just shared this useful info with us.
Please keep us informed. Thanks for sharing.
[…] out this excellent post by Tim […]