ConfigSource attribute on system.serviceModel section

摘要:ConfigSource attribute on system.serviceModel section


The configSource attribute was firstly introduced in .NET framework 2.0 to support external configuration files.

This attribute can be added to any configuration section to specify a an external file for that section. Using an external configuration source can be useful in many scenarios. For instance, you could place a section into an external configSource if you need an easy method to swap settings for the section depending on the environment (development, test, or production), or  you need granular control over permissions.

Unfortunately, the system.serviceModel section group does not support this attribute. If you try to add it, you will receive the following exception:

The attribute 'configSource' cannot be specified because its name starts with the reserved prefix 'config' or 'lock'

What I found out is that you can use this attribute on the different sections under system.serviceModel such as services, behaviors or bindings.

For instance, the configuration file could look like this,

 

   

   

   

   

   

   

 


 And then, each file contains the corresponding section.

Services.config

 

          behaviorConfiguration="CalculatorServiceBehavior">

   

     

       

     

   

   

   

              binding="netTcpBinding"

              bindingConfiguration="Binding1"

              contract="Microsoft.ServiceModel.Samples.ICalculator" />

   

   

              binding="mexHttpBinding"

              contract="IMetadataExchange" />

 


Bindings.config

 

   

            closeTimeout="00:01:00"

            openTimeout="00:01:00"

            receiveTimeout="00:10:00"

            sendTimeout="00:01:00"

            transactionFlow="false"

            transferMode="Buffered"

            transactionProtocol="OleTransactions"

            hostNameComparisonMode="StrongWildcard"

            listenBacklog="10"

            maxBufferPoolSize="524288"

            maxBufferSize="65536"

            maxConnections="10"

            maxReceivedMessageSize="65536">

     

                    maxStringContentLength="8192"

                    maxArrayLength="16384"

                    maxBytesPerRead="4096"

                    maxNameTableCharCount="16384" />

     

                      inactivityTimeout="00:10:00"

                      enabled="false" />

     

       

     

   

 


Behaviors.config