Monthly Archives: April 2009

How to view default values for a WCF binding

… or create a custom binding from a build-in binding.
… or create an administrative XML-based configuration from an administrative programmatic configuration.

Below codes does all that:

// Specify the source binding
// - Programmatic binding
// - Administrative XML-based binding
// - Convert to custom binding

/* Programmatic binding */
var binding = new BasicHttpBinding();
binding.TransferMode = TransferMode.Streamed;
binding.MaxReceivedMessageSize = 10000;

/* Administrative XML-based binding */
// var binding = new BasicHttpBinding("basicHttp");

/* Convert to custom binding */
// var wsBinding = new WSHttpBinding("wsHttp");
// var binding = new CustomBinding(wsBinding);

string outputConfigFile = "out.config";

Configuration machineConfig = ConfigurationManager.OpenMachineConfiguration();

var fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = outputConfigFile;
fileMap.MachineConfigFilename = machineConfig.FilePath;

Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
config.NamespaceDeclared = true;

var scg = new ServiceContractGenerator(config);

string sectionName, configName;
scg.GenerateBinding(binding, out sectionName, out configName);
config.Save();

The programmatic source binding will create a configuration file with all default values for the BasicHttpBinding except for TransferMode and MaxReceivedMessageSize attributes like so:

<basichttpbinding>
    <binding name="BasicHttpBinding" 
             closeTimeout="00:01:00" 
             openTimeout="00:01:00" 
             receiveTimeout="00:10:00" 
             sendTimeout="00:01:00" 
             allowCookies="false"
             bypassProxyOnLocal="false" 
             hostNameComparisonMode="StrongWildcard"
             maxBufferSize="65536" 
             maxBufferPoolSize="524288" 
             maxReceivedMessageSize="10000" 
             messageEncoding="Text" 
             textEncoding="utf-8" 
             transferMode="Streamed"
             useDefaultWebProxy="true">
        <readerquotas maxDepth="32" 
                      maxStringContentLength="8192" 
                      maxArrayLength="16384" 
                      maxBytesPerRead="4096" 
                      maxNameTableCharCount="16384" />
        <security mode="None">
            <transport clientCredentialType="None" 
                       proxyCredentialType="None" 
                       realm="" />
            <message clientCredentialType="UserName" 
                     algorithmSuite="Default" />
        </security>
    </binding>
</basichttpbinding>

I found this tip by Brian McNamara on the MSDN WCF forum.

World’s first electronic annual general meeting

Today I just witness the electronic annual general meeting for the investment company SparIndex. This is the first 100% electronic annual general meeting ever.

The stakes was high, especially for the system owner VP Securities as journalists and photographs wandered around the offices ready to report success or failure in the media.

My job as a technical consultant, together with a handful of other techies, was to monitor the solution during the live annual general meeting. Our job was to prevent any technical glitches or in the event of a crash recover as fast as possible.

The tension was high right up to the last minute before the premiere, but everything went smooth. 🙂

Screenshot of the World’s first electronic annual general meeting

Screenshot of the World’s first electronic annual general meeting