Ben McCallum's Blog

Dissecting ASP.NET MVC3, CSS3, HTML5, jQuery and a whole lot of other things ending with numbers…

Archive for the category “WCF Web Services”

Mads Kirstensen’s Free Image Optimiser

I found this a while ago but never really tried using it until just now:

This is a plugin by Mads Kristensen a Program Manager at Microsoft who does a lot of work with Visual Studio tooling. He wrote this tool which lets you right click a folder of images or a single image in the Visual Studio Solution Explorer and select “Optimise images”.

using Image Optimiser

It then performs some magic – calling image optimisation web services to optimise the images by removing unneeded metadata in the image file. It can also generate base64 strings for embedding images in CSS stylesheets.

On average I see around a 30% saving in file size and the optimisation is lossless meaning the image quality remains the same. It’s a quick and easy thing to do just before a new deployment to make browsing our websites much faster.

Just be sure to check out the images you want to be optimised otherwise the plugin will just skip them.

Hope you find it useful.


WCF Web Service Wrapper: Closing, Disposing and Aborting best practices

When calling methods on a WCF web service it’s best practise to do the following:
(To avoid the using keyword with WCF clients:

But all this garbage is exhausting and repetitive when you are calling the web service in many places.

One solution is to inherit IDisposable and implement Dispose() for the web service but you’ll need to do that for every web service you consume meaning more duplicate code and using partial classes in combination with the auto-generated code from your service reference in Visual Studio.

Instead, I’ve come up with a hybrid of many ideas on the web that essentially wraps the WCF web service, performs any method calls and closes/disposes/aborts the connection gracefully:

WCF Service Wrapper class


An example of usage:

It’s a very elegant, and highly re-usable piece of code that I’ll be using in all apps that consume WCF web services. Using generics the same Service class can make calls to different services meaning you can plug-n-play this code in all your client apps and never write a try catch finally block around WCF service calls again. And if you ever need to customise the way service calls are handled, errors logged, etc. it’s all in one spot! Enjoy!

Post Navigation