Maintenance and retrieval of service URLs

2

I'm working on a Web Forms project that has a DLL, and in that DLL there are references to external services. We have 3 environments (development, homologation and production) and for each environment there is a specific URL for each of the services, in its version for the respective environment.

I'm having trouble managing the URLs of these services. In the WebForms project I have web.config where I can use XML Transformations to store key / value sets, and this would solve my problem. However, in the DLL I only have a app.config file and it does not support transformations. What is the best way to get my solution adapted to integrate with the correct environment, based only on the Configuration used during the Publish process?

Just to highlight my current template: I create an entry in the Web.Config with the service URL

<add key="UrlServicoCep" value="http://url_dev/servico.asmx" />

Then I retrieve this value and step it as a parameter in the instantiation of the class where the service is used:

string urlServico = ConfigurationManager.AppSettings["UrlServicoCep"];
var dao = new CepDAO(urlServico);

Summary: I want to generate a package for the desired environment (approval or production) and that this package generation already has the correct URL applied to the web services that I use.

    
asked by anonymous 10.07.2014 / 23:04

1 answer

2
  

However, in the DLL I only have one app.config file and it does not support transformations.

It does. Just install the following extension in your Visual Studio:

link

EDIT

If you do not want to use the extension, I believe the method is already quite close to the appropriate one. I would just make a little modification:

string urlServico = ConfigurationManager.AppSettings["UrlServicoCep"] ?? "http://url_default/servico.asmx";
var dao = new CepDAO(urlServico);
    
10.07.2014 / 23:10