Snippet: Construct WCF Binding from string (xml)

Here is a snippet to convert a bindingconfiguration xml fragment into a Binding (with a few limitations). Configuration configSystem = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);var bindingSection = BindingsSection.GetSection(configSystem);string customConfig = “<netTcpBinding><binding name=\”netTcpBinding\” maxReceivedMessageSize=\”12345\” hostNameComparisonMode=\”Exact\” /></netTcpBinding>”;// another example: // string customConfig = “<binding name=\”basicHttpBinding\” messageEncoding=\”Mtom\” maxReceivedMessageSize=\”14000\” allowCookies=\”True\” /></basicHttpBinding>”;bindingSection.SectionInformation.SetRawXml(string.Format (“<bindings>{0}</bindings>”,customConfig));BindingCollectionElement bindingCollectionElement = null;foreach (BindingCollectionElement bicoelem in bindingSection.BindingCollections){    if (0 < bicoelem.ConfiguredBindings.Count)    {        bindingCollectionElement = bicoelem;        break;    }}var newBinding = (Binding)bindingCollectionElement.BindingType.Assembly.CreateInstance(bindingCollectionElement.BindingType.FullName);IBindingConfigurationElement bEleEx = bindingCollectionElement.ConfiguredBindings[0];bEleEx.ApplyConfiguration(newBinding); At this point the newBinding is configured with the configurationoptions you added in the “customConfig” string. HTH


Mixing MEF and PIAB

The Policy Injection Application Block (PIAB) provides a way to dynamically apply cross-cutting concerns by configuration or attributes. The combination of this technique and composition using Managed Extensibility Framework (MEF) can be realized through the use of a factory method as demonstrated here. The example demonstrates PIAB by the use of a CallHandler specifically for…


Upgrade SQL CE Database from 3.1 to 3.5

var engine = new System.Data.SqlServerCe.SqlCeEngine(“Data Source=” + filename); engine.EnsureVersion35(filename);   –HELPER CLASS—     public static class SqlCeUpgrade     {         public static void EnsureVersion35(this SqlCeEngine engine, string filename)         {             try             {                 SQLCEVersion fileversion = DetermineVersion(filename);                 if (fileversion == SQLCEVersion.SQLCE20)                     throw new ApplicationException(“Unable to upgrade from 2.0 to 3.5”);                …


Just Released: Microsoft Enterprise Library 5.0

See details here: and read Grigori’s post here:  


Clean-up your desktop with fences

Neat tool for grouping “stuff” on your desktop – fences from – go here


New Feature Builder Power Tools

Those of you interested in Software Factories and Visual Studio Automation may find it relevant to investigate the new Feature Builder Power Tools. I will be happy to hear about your experiences and suggestions. Exerpt from landingpage: Feature Builder is a Power Tool for Visual Studio 2010 (preview) which helps you easily create rich Visual Studio extensions. These…


Free Book: A Guide to Claims-Based Identity and Access Control

Another free book from our Patterns&Practices team about something that you know you ought to know a little about 🙂 – Claims Based Identity and Access Control. Get the Book here – Code samples here –  


Dynamically Loading ModuleCatalog in Composite (PRISM) Silverlight Application

Intercept the Run method of your bootstrapper by defining a new Run method, fetch the list of modules (list trimmed to the user in question of course) and populate the catalog from this. poc code? Here you are (note I am using a custom RIA domain service to trim the list of modules) public class…


Code Contracts

 pre-conditions, post-conditions, object invariants in .NET – go here


Share sourcecode between Silverlight and WPF Applications

Sharing code between Silverlight and WPF Applications has been a returning wish from several of the customers in our Microsoft Innovation Center in Denmark. The base class libraries are very similar, but obviously something is missing in the 3-4 MB Silverlight download you just installed on that iMac in your girlfriends officespace… therefore if you…