0

I am in need of help with manipulating the web.config of a site programmatically via C#. The site in question hosts a Silverlight 5 application which communicates with the server runtime via WCF RIA services.

The code that I am writing is part of a bootloader for an automated build-deploy-test scenario aimed at testing the WCF Ria service stack. The issue at question is that in order to test the services properly the unit test code needs to be able to communicate with the Ria Services via a new soap endpoint.

To effectively make this work the site needs a copy of the Microsoft.ServiceModel.DomainServices.Hosting dll in it's bin folder, and a new soap endpoint which would make the domain services config section look like the following:

<system.serviceModel>
    <domainServices>
        <endpoints>
            <add name="OData" .../>
            ***<add name="Soap" type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>***
        </endpoints>
    </domainServices>
</system.serviceModel>

While I do believe I could modify the web.config via the C# xml api, I was wondering if there is another way to do so via the ConfigurationManager?

Cœur
  • 37,241
  • 25
  • 195
  • 267
bleepzter
  • 9,607
  • 11
  • 41
  • 64

1 Answers1

-1

I would do config manipulation as part of the build script.

I am currently using YDeliver as the build/deploy framework in my project and since it runs on top of Powershell, I manipulate XML using the xml api in posh.

Srikanth Venugopalan
  • 9,011
  • 3
  • 36
  • 76
  • Config manipulation is done as part of deployment script and I can't change it. It also doesn't make sense to do this in the "build" script because the testing is done in a "build-deploy-test" scenario on blank VM's running Windows Server 2008 R2 or Windows Server 2012. Furthermore I can't change the installer or else I have to have two - one for the testing and one for production. Since I am trying to test production quality code and produce "validation tests results" having two completely different installers defeats the purpose due to compliance reasons. – bleepzter Mar 05 '13 at 04:39
  • Also the reason why it is -1, is because while it is a decent suggestion, there is no need to learn another language; the question was C# specific. Furthermore, the answer is fairly generic - it is obvious that the config file has to be modified. The problem in doing so is that when the web application is deployed to IIS, the config file gets used by the IIS worker process (the app pool under which the site runs). The ConfigurationManager (System.Configuration) api and the specific ConfigSection definitions provide for a method that avoids the file lock to directly manipulate the config file. – bleepzter Mar 05 '13 at 04:58
  • @bleepzter - fair enough, I see where you are coming from. In my projects so far, we have tried to separate the concerns (application holding just the business logic etc) and configuration management is done via buildscripts, buildconfig and CI tool. Though I agree with you on having a single installer (artifact), I feel it could be the installer controlling the configuration as opposed to the application. – Srikanth Venugopalan Mar 05 '13 at 05:22