DCSIMG
Spliting WCF config files - Manu Cohen-Yashar's Blog

Manu Cohen-Yashar's Blog

Spliting WCF config files

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'

"configSource" attribute is a property comes from the  section Information class.
Every ConfigurationSection in .net framework 2.0 configuration scheme system
has a property of a section Information where the config source is declared.

 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,

<configuration>

 

  <system.serviceModel>

    <services configSource="Services.config" >

    </services>

 

    <bindings configSource="Bindings.config">

    </bindings>

 

    <behaviors configSource="Behaviors.config">

    </behaviors>

 

  </system.serviceModel>

 

</configuration>

 And then, each file contains the corresponding section.

Services.config

<services>

  <service name="Microsoft.ServiceModel.Samples.CalculatorService"

          behaviorConfiguration="CalculatorServiceBehavior">

    <host>

      <baseAddresses>

        <add baseAddress="http://localhost:8000/servicemodelsamples/service"/>

      </baseAddresses>

    </host>

    <!-- this endpoint is exposed at: net.tcp://localhost:9000/servicemodelsamples/service  -->

    <endpoint address="net.tcp://localhost:9000/servicemodelsamples/service"

              binding="netTcpBinding"

              bindingConfiguration="Binding1"

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

    <!-- the mex endpoint is exposed at http://localhost:8000/ServiceModelSamples/service/mex -->

    <endpoint address="mex"

              binding="mexHttpBinding"

              contract="IMetadataExchange" />

  </service>

</services>

Bindings.config

<bindings>

  <netTcpBinding>

    <binding name="Binding1"

            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">

      <readerQuotas maxDepth="32"

                    maxStringContentLength="8192"

                    maxArrayLength="16384"

                    maxBytesPerRead="4096"

                    maxNameTableCharCount="16384" />

      <reliableSession ordered="true"

                      inactivityTimeout="00:10:00"

                      enabled="false" />

      <security mode="Transport">

        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />

      </security>

    </binding>

  </netTcpBinding>

</bindings>

Behaviors.config

<behaviors>

  <serviceBehaviors>

    <behavior name="CalculatorServiceBehavior">

      <serviceMetadata httpGetEnabled="true" />

      <serviceDebug includeExceptionDetailInFaults="False" />

    </behavior>

  </serviceBehaviors>

</behaviors>

Comments

public class Alon : ISmartHome, ICPP, IHomeServer, IMediaCenter said:

Today, I had to show how to host many services in one place. Since I did not find many example on the

# March 12, 2008 11:54 PM

Anjum rizwi said:

I have implemented using your approach but we see some syntax error on "The '<bindings>' element is not declared" in editor.

Funtiononality is working file.

Thank You,

ANjum rizwi

# April 28, 2009 9:29 AM

Anjum rizwi said:

One more "ConfigSource attribute is not declared" in VS 2008

# April 28, 2009 9:35 AM

Deepa said:

I'm using the NET Framework 3.5. I'm getting error that "The configSource" attribute is not declared when I use configSource attribute for Services / bindings/Behaviors.

# April 28, 2009 12:44 PM

anonymous said:

How come this post is exactly like an older post from Pablo M. Cibraro (aka Cibrax)?

weblogs.asp.net/.../configsource-attribute-on-system-servicemodel-section.aspx

# December 17, 2009 7:50 PM

cibrax said:

This is an extact copy of my blog post. Could you please add my name on it or remove it from your blog ?.

# December 17, 2009 8:17 PM

Twitter Trackbacks for Spliting WCF config files - AppliSec [microsoft.co.il] on Topsy.com said:

Pingback from  Twitter Trackbacks for                 Spliting WCF config files - AppliSec         [microsoft.co.il]        on Topsy.com

# December 17, 2009 9:28 PM

Fiesta Party Rentals Santa Barbara, Ford Fiesta Heater said:

Pingback from  Fiesta Party Rentals Santa Barbara, Ford Fiesta Heater

# May 21, 2010 11:45 PM

Scamp Plymouth Called Dodge Rampage, Plymouth Scamp Used Gran Fury Truck Parts - 461.cmanager.org said:

Pingback from  Scamp Plymouth Called Dodge Rampage, Plymouth Scamp Used Gran Fury Truck Parts - 461.cmanager.org

# May 23, 2010 4:29 PM

1981 - 2003 @ 760i Second Hand Yahoo Autos, 760i Factory Grooved - 277.an74.com said:

Pingback from  1981 - 2003 @ 760i Second Hand Yahoo Autos, 760i Factory Grooved - 277.an74.com

# May 31, 2010 10:10 AM

kolept said:

after converting project to vs2010 version,the build is failling in the app.config

<system.serviceModel>

   <behaviors configSources="SharedWcfBehaviors.config"/>

   <bindings configSource="SharedWcfBindings.config"/>

   <client configSource="SharedWcfClients.config"/>

 </system.serviceModel>

But previously was working fine with vs 2008 sp1.

The error shown as the config source attribute is not allow , appreciate with some help here.

# June 1, 2010 5:07 AM

No said:

You should update your post to indicate this is no longer a valid solution in later versions of .NET.  3.5 and 4.0 do not support configSource in any serviceModel children.

# December 15, 2010 2:10 AM

Commentator said:

My solution is entirely 4.0 and the solution posted here is perfectly valid.

The external files must be discoverable, e.g. in the same directory or sub-directory of the original config file with appropriate file paths. If using a web project then these changes must going into the web.config file. If using a custom app.config file then these changes must go in there. Pay attention to which config file is loaded in the app domain.

# August 17, 2011 6:27 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: