locked
window service host WCF can not read web.config RRS feed

  • Question

  • Hi!
    I have a WCF project. But my IIS in my Server can't run. So i have to host in window service.
    There, i can't read appsettings in web.config file in WCF project. anyone answer me why? and how?
     <appSettings>
        <add key="serverHostName" value="192.168.1.76"/>
        <add key="serverPort" value="8583"/>
        <add key="clientHostName" value="127.0.0.1"/>
        <add key="clientPort" value="8583"/>
      </appSettings>
    Tuesday, January 20, 2009 3:39 AM

Answers

  • In other words if your service executable is called MyService.exe you will need a config file called MyService.exe.config. web.config is for web applications only. Visual Studio helps you a bit here you add an "application configuration file" to the project (which will be called app.config by Visual Studio). This file then gets copied out to the same directory as the .exe with the correct name by the build process (so if you make config changes you will need to run a build to get them copied out to the right directory).

    You need to put the same system.serviceModel and appSettinogs values in this app.config file as you have in your web.config
    Richard Blewett, thinktecture - http://www.dotnetconsult.co.uk/weblog2
    Tuesday, January 20, 2009 7:51 AM

All replies

  •  Just take a normal app.config file (for your host application) instead of the web.config.
    • Proposed as answer by Will.Rogers Tuesday, January 20, 2009 12:55 PM
    Tuesday, January 20, 2009 7:24 AM
  • In other words if your service executable is called MyService.exe you will need a config file called MyService.exe.config. web.config is for web applications only. Visual Studio helps you a bit here you add an "application configuration file" to the project (which will be called app.config by Visual Studio). This file then gets copied out to the same directory as the .exe with the correct name by the build process (so if you make config changes you will need to run a build to get them copied out to the right directory).

    You need to put the same system.serviceModel and appSettinogs values in this app.config file as you have in your web.config
    Richard Blewett, thinktecture - http://www.dotnetconsult.co.uk/weblog2
    Tuesday, January 20, 2009 7:51 AM