0

In my windows service I have 2 web references

My windows service only contains an app.config not a web.config

my app config looks like this:

    <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="MyFirstWindowsService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
    </startup>
    <system.serviceModel>
        <bindings />
        <client />
    </system.serviceModel>
    <applicationSettings>
        <MyFirstWindowsService.Properties.Settings>
            <setting name="MyFirstWindowsService_postDataToMapicsWC_XAXSSTRN"
                serializeAs="String">
                <value>http://TESTDEV/web/services/XAXSSTRN.XAXSSTRNHttpSoap11Endpoint/</value>
            </setting>
            <setting name="MyFirstWindowsService_com_goodmanmfg_testdev_GETITMINFO"
                serializeAs="String">
                <value>http://TESTDEV/web/services/GETITMINFO.GETITMINFOHttpSoap11Endpoint/</value>
            </setting>
        </MyFirstWindowsService.Properties.Settings>
    </applicationSettings>
</configuration>

[![enter image description here][1]][1]

the problem is my web services when i click on them the URL field is still saying

"Web reference URL" http://PROD/web/services/XAXSSTRN.XAXSSTRNHttpSoap11Endpoint [![enter image description here][2]][2]

what is the end goal? To release this windows service to dev and prod environments without having to rebuild the entire solution.

The ideal behavior is :

  1. Build the latest code in dev mode (test it, if all test good then , step 2)

  2. Provide an app.config file with prod urls to dropped inside the folder

  3. Release

    As you can see what I am trying to avoid is the need of dropping the file manually changing those 2 web services , rebuilding the solution AND THEN releasing...

cocopan
  • 109
  • 3
  • 19
  • I personally use a local text file with the path to my webservices and simply code the endpoint by hand using the value in the text file. Very simple. You only need to add web reference once to at least have the intellisence once you are using it. When swapping i just have 2 host on the web server and update one and swap everyone on that path. The next time i do it i update the other webfolder and swap everyone on it – Franck Jul 06 '18 at 19:29

1 Answers1

1

Classic ASP.NET apps get their configuration from a hierarchy of web.config values. Other apps (console applications, Windows Forms apps, WPF, Services, ...) get their configuration from a configuration file named [NameOfExe].exe.config (and occasionally from [NameOfAssembly].dll.config. That file is located in the same folder as the exe itself.

For example, if your service is MyWcfService.exe, you will very likely find a MyWcfService.exe.config file in the same folder (for example, in the bin/debug folder). Its contents should be the same as your app.config.

Visual Studio makes this all "just work" by creating an app.config file in your source folder and then, at build time, copying the contents of that file to the appropriately named [NameOfExe].exe.config file in the same folder as the EXE.

In the normal case, you might have one set of URLs (and perhaps other data) for your dev environment, another for QA, another for Integration Test and another for Prod. You can manage this through the use of configuration transforms.

I think this goes some way towards answering your questions. In summary

  1. App.config files have nearly the same capabilities as web.config files
  2. App.config files get "compiled" to [NameOfExe].exe.config files at build time and placed in the same folder at the EXE
  3. Configuration transforms may help you out with managing your URLs

Your other choice is managing a set of [NameOfExe].exe.[Environment].config files and manually putting them in the right place.

Flydog57
  • 6,851
  • 2
  • 17
  • 18
  • hello flydog57 Thanks for your answer. I have a couple of questions... In my app.config when I change the references they don't get changed in my web references which I guess is expected BUT when I change my web references and rebuild the project, my app.config also doesn't get updates, is this also expected??? also I have tried dropping the files as you suggested (nameofEXe].exe but I haven't had any luck either. – cocopan Jul 09 '18 at 13:41
  • Back when I was building my windows service i found to point it to obj/debug/myFirstWindowsService.exe but inside this folder i don't have any file.exe.config. I have changed those files in other folders but that doesn't seem to do anything either. Do you know why this may be happening? – cocopan Jul 09 '18 at 13:53
  • When you add a "web reference" to a project, you are telling VS "go to this URL, pull down the metadata from the web service, and build a proxy for me". The proxy stays the same until you "Update" the web reference. There's no natural link between the web reference and where you point your web service (you can add a local web reference but point to a distant web service that uses the same WSDL). The app.config URLs are the ones you are actually going to access, not where you pulled the metadata from. You can fiddle those URLs directly or use the WCF configuration tool. – Flydog57 Jul 09 '18 at 15:09
  • As to why the app.config file isn't acting like it should... Did you add it to the project by adding a config file, or by adding it some other way. I'm not sure where the magic "copy app.config renaming it to myexe.exe.config" logic resides (I've casually looked before, but never found it, and never dug very deeply) – Flydog57 Jul 09 '18 at 15:11