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

1

Writing Test Code with Impersonation

Some of your (unit) tests may be required to run with predefined credentials, and if all your tests should run as one single identity your might as well use the command line runas.exe tool to start your testrunner (or whatever your favorite naming for this is). In some (rare?) occasions you may need to do…

2

EntLib 3.0 Released

The P&P team has finished the third major release of the enterprise library. See Tom’s post for more information. Try the new WCF integration with logging, exception handling and validation application blocks. Download from MSDN.   

1

WF in IIS Hosted WCF Service

Hosting Workflow in WCF is described in the before mentioned article by Jeremy Boyd. In the article it is shown how to create an extension class for Workflow, and add this to the ServiceHost Extension collection. The code presented in the article is something like: using (ServiceHost serviceHost = new ServiceHost(new ExpenseService())) {   WfWcfExtension…

1

Externalize your Communication Protocol Details with WCF

In general the Web Service client proxy generated by “Add Web Reference” in Visual Studio is all you need to start talking to a Web Service. Some of you may need to present a certificate to the remote server you are calling and for this purpose you would typically populate the ClientCertificates collection on the…

0

Unit Testing WCF Services

A colleague of mine recently wrote about seperation of concerns in relation to unit testing WCF services.  It may be possible to expose a library directly in WCF but I would rather see an architecture like the one presented in the Service Software Factory with a clear separation of concerns. In my opinion it makes…

3

Nice WCF Blog!

Just stumbled over Nicholas Allens Indigo blog the other day… lots of info..go visit.. Here

1