Most of the sample from Microsoft have so far been more about HOW to use “Oslo”, rather then WHY and WHEN. This has brought many developers to struggle about what to make out of “Oslo”, and how to put it in good use.
There are, however, several very interesting community posts about Oslo. But most of them are about M Grammar, and very few (I haven’t seen any) has been about the “Repository”.
M Grammar, is without a doubt a more “sexy” technique, as the Repository is nothing more than a SQL store for your models. – BUT I’m willing to bet that the Repository will play a very significant part in the future of any Microsoft technology. By writing this article, I hope to broaden your vision of how to use “Oslo”, and envision where Microsoft is going with the it.
Service Configuration => “Oslo” Repository;
A service host, hosts one or more services. It is created by a service host factory which, by default, loads all service configurations (bindings, services and behaviors) from one configuration file. The default factory is System.ServiceModel.Activation.ServiceHostFactory.
The samples in this post will show you how you could load the configurations for all your services from ONE “Oslo” Repository, rather than from many configuration files. As if all your services would share the same config file.
The sample above would of course work for any number of web servers accessing the same Repository database.
To accomplish this we need:
- A “Oslo” model representing system.serviceModel. The January release of “Oslo” where shipped with the system.serviceModel model. However it was cut out in the May release, so I just created my own.
- A custom service host factory that loads Services and endpoints, along with all bindings and behaviors. I didn’t bother to make this to generic, so it only supports basicHttpBinding, wsHttpBinding, netTcpBinding and of course mexHttpBinding.
– “So what?”
Actually, I think this is a pretty big deal. Having one single repository for all your services, means one single store for managing and configuring these services. – And what better tool to use than the “Oslo” Quadrant!
Try it out:
- If you haven’t already installed the Oslo May CTP release, you can find it at the “Oslo” Developer Center.
- Download the zip file and open the bLogical.ServiceModel.m file using “Intellipad”.
- In “Intellipad”, switch to “SQL-Preview” by using the “M mode” in the menu bar.
- Open SQL Management Studio, create a new query window and select the Repository database.
- Copy the T-Sql from “Intellipad”, paste it in to the query window and execute it. This will create all the Tables, and populate them with sample data.
- Open Visual Studio 2008, and create a new WCF Service by selecting “New Web site”. Don’t change the name of the service, as the samples created in step 5 assumes your service is called “Service”, and its interface is called IService. If you do want to change the name or use it for an already existing project, make sure to to do the changes in the repository.
- Add the bLogical.Oslo.ServiceHostFactory project to your solution.
- Open your .svc file and add the bLogical service factory:
<%@ ServiceHost
Language="C#"
Debug="true"
Service="Service"
CodeBehind="~/App_Code/Service.cs"
factory="bLogical.Oslo.ServiceHostFactory.ServiceHostFactory"
%>
Run the service!
HTH
Special thanks to Yossi Dahan, for encouraging me to do this article.
//Mikael