Bernie Cook's Blog

Azure, C#, .NET, Architecture & Related Tech News

Programmatic SSL AppFabric Cache Integration

Leave a comment

I recently integrated Windows Azure’s AppFabric Cache into a solution I’ve been working on and went down the programmatic route as opposed to modifying my solution’s application configuration files.  I initially modified the web.config and app.config files for my web and worker roles respectively, just to see how easy it was to implement caching via that method, and I can say with confidence that Microsoft have made it a complete breeze.  However, my requirements meant that I had to programmatically create the DataCacheFactory and connect to the SSL endpoint for an added layer of security.

This wasn’t exactly rocket science, and after reading the following articles I was ready to start coding:

The one thing I couldn’t find any information on was how to connect to the SSL endpoint programmatically. So I did a bit more reading into the DataCacheSecurity object and realised that all I needed was to use one of it’s overloaded constructors which provided the option to enable SSL.

So instead of instantiating the DataCacheSecurity object like so:

DataCacheSecurity dataCacheSecurity = new DataCacheSecurity(secureAuthenticationToken);

I added the following parameter:

DataCacheSecurity dataCacheSecurity = new DataCacheSecurity(secureAuthenticationToken, true);

(See the How to Configure a Cache Client Programmatically for Windows Azure Caching article for the remainder of the code)

In addition, I had to ensure I was using the correct cache port of 22243, but if you’ve read this far I’m sure you’ll have guessed that already. Everything ran perfectly from here and after a few hours of testing my solution was up in and running in the cloud.

Programmatic Integration or Configuration Integration?

Which approach you take depends on the solution at hand.  I had a solution that was similar to the one illustrated below (slightly more complex but I don’t want to let that sidetrack the point I’m trying to make).  This particular solution has to be able to run in several environments; development, staging and production (as per the norm) as well as a sandbox environment for staff who work abroad that need a place to practice using new features before their released.  Using the default web.config and app.config didn’t provide the flexibility required – I needed to be able to configure my particular environment’s service configuration file to use the correct caching namespace. So for me programmatically configuring my caching client was the only option.

(These icons can be sourced from David Pullman’ s Blog)

Additional Points

If you are looking to implement AppFabric Caching then I’d recommend reading the following points (please excuse me if I’m stating the obvious):

  • Ensure you have the Windows Azure SDK v1.6 (November 2011) or greater
  • Be careful where you’re sourcing your information, some of it can be dated and cause confusion, or just not work anymore
  • The updates Microsoft made to their Windows Azure website back in December 2011 are fantastic so it’s a good place to start if you’re interested in learning more about, or implementing, a given Azure service
Advertisements

Author: Bernie

I currently live and work in the UK, just outside of London. I've been working in IT for 15+ years and in that time have solved many technical problems via blogs, forums, tutorials etc. and feel like I should be giving something back. This blog post is my way of contributing and I hope it proves just as useful to others as their contributions have to me.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s