Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I split system.serviceModel into a separate .config file?

I want to separate my system.serviceModel section of the web.config into a separate file to facilitate some environment settings. My efforts have been fruitless. When I attempt it using this method. The wcf code throws an exception: "The type initializer for 'System.ServiceModel.ClientBase 1 threw an exception. Can anyone tell me what I am doing wrong?

Web.config:

<configuration>
  <system.serviceModel configSource="MyWCF.config" />
  ....

MyWCF.config:

  <system.serviceModel>
    <extensions>
      ...
    </extensions>

    <bindings>
      ...
    </bindings>

    <behaviors>
      ...
    </behaviors>

    <client>
       ...
    </client>

  </system.serviceModel>
like image 914
Mr Bell Avatar asked May 11 '10 19:05

Mr Bell


2 Answers

You cannot "externalize" the <system.serviceModel> section group - since it's a configuration section group - but you can definitely externalize each of the bits inside it:

<system.serviceModel>
    <behaviors configSource="behaviors.config" />
    <bindings configSource="bindings.config" />
    <extensions configSource="extensions.config" />
    <client configSource="client.config" />
    <services configSource="services.config" />
</system.serviceModel>

In the .NET configuration system, any configuration section can be externalized - each configuration section has a configSource attribute (even though Visual Studio sometimes complains and claims the contrary.....) - but not configuration section groups.

Unfortunately, these two are hard to tell apart - you need to consult the MSDN library or documentation to find out.

You should also check out Jon Rista's three-part series on the .NET configuration system up on CodeProject.

  • Unraveling the mysteries of .NET 2.0 configuration
  • Decoding the mysteries of .NET 2.0 configuration
  • Cracking the mysteries of .NET 2.0 configuration

Highly recommended, well written and extremely helpful!

like image 180
marc_s Avatar answered Oct 21 '22 03:10

marc_s


Try this suggestion:

http://weblogs.asp.net/cibrax/archive/2007/07/24/configsource-attribute-on-system-servicemodel-section.aspx

like image 27
John Bledsoe Avatar answered Oct 21 '22 04:10

John Bledsoe