Cross Post from Ron Jacobs blog
This morning I saw a message post on the .NET 4 Windows Workflow Foundation Forum titled Load XAMLX from database. I’ve been asked this question many times.
How can I store my Workflow Service definitions (xamlx files) in a database with IIS and AppFabric?
Today I decided to create a sample to answer this question. Lately I’ve been picking up ASP.NET MVC 3 so my sample code is written with it and EntityFramework 4.1 using a code first approach with SQL Server Compact Edition 4.
AppFabric.tv – How To Build Workflow Services with a Database Repository
Step 1: Create a Virtual Path Provider
Implementing a VirtualPathProvider is fairly simple. The thing you have to keep in mind is that it will be called whenever ASP.NET wants to resolve a file or directory anywhere on the website. You will need a way to determine if you want to provide virtual content. For my example I created a folder in the web site called XAML. This folder is empty but I found that it has to be there or the WCF Activation code will throw an exception.
When I want to activate a Workflow Service that is stored in the database I use a URI that will point to this directory like this http://localhost:34372/xaml/Service1.xamlx
Step 2: Create a VirtualFile class
The VirtualFile class has to load content from somewhere (in this case a database) and then return a stream to ASP.NET. Performance is a concern so you should definitely make use of caching when doing this.
Step 3: Register the Virtual Path Provider
Finally you register the provider and you will be on your way.
Twitter: @ronljacobs https://twitter.com/ronljacobs