I have a Visual Stuido 2010 website project (not web application). I need to provide the ability to make a web service call, either ad-hoc from a website button or scheduled. So I create a c# library containing a WCF call to the target web service. I then add a reference to my library from the website. I am now able to call a public method on my library that then call the webservice – great!
My problem is, the website seems to insist on having the system.servicemodel web.config entries required for the call to the web service. Although this works, it means I have two places to maintain them – in the web.config of the client website and the app.config of my c# library. I have also created a c# console application (to trigger the web service call on a schedule) which references the library app, this too requires a copy system.servicemodel entries in its app.config. The same applies for connection strings.
Does anyone know if there’s an easy way to avoid this reliance on having duplicate web.config / app.config entries spread through various projects of the solution?
Thanks,Rob.
You could “externalize” your relevant config sections into separate files, and reference those from both
app.configas well as yourweb.config.Any .NET configuration section can be stashed into an external config file, so you can write:
Now, your external files will look exactly like the relevant config section inside your config:
bindings.config:Note: Visual Studio’s editor will complain about the
configSource=attribute – but the Intellisense is mixed up – theconfigSourceattribute is present on each configuration section, and it does work just fine!Note #2: you cannot externalize the entire
<system.serviceModel>since that is a configuration section group – and those do not have any means to be put into external files, unfortunately.