none
AppSettings tag in app.config file of a WCF RRS feed

  • Question

  • Hi,

    I am developing a wcf and am using some hard coded values as of now for testing. However I want to put these values in the app.config file so that values can be easily changed while moving from dev to staging/ Prod environment.

    Where should I put these key-value pair in the app.config file of wcf?

    Wednesday, March 19, 2014 6:08 AM

Answers

  • Hi,

    We should have an app.config file in our VS project. If you don't, you can add one to the project by right clicking the project within the Solution Explorer, then Add, then New Item. From the "Add New Item" screen, you should see "general" among the common items on the left. Double click the first item "Application Configuration File" in the middle screen and you should be good to go.

    From there, you can add your XML tags.

    Typical Format in the app.config looks like this:

     <?xml version="1.0"?>
     <configuration>
        <startup>
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
        </startup>
        <appSettings>
           <add key="HostDomain" value="\\somedatabaseserver\DatabaseUnitTests" />
           <add key="Port1" value="" />
         </appSettings>
     </configuration>

    Depending on how you compile your WCF service (which format), you should get witin your \project\bin\debug directory a .config file with the same name as your executable or DLL.

    Then reading the config file in code is done with something like this:

      Dim confReader As System.Configuration.AppSettingsReader = New System.Configuration.AppSettingsReader
      Domainvalue = confReader.GetValue("HostDomain", GetType(System.String)).ToString()
      Portvalue = confReader.GetValue("Port1", GetType(System.String)).ToString()

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Thursday, March 20, 2014 6:10 AM
    Moderator

All replies

  • Hi IMSunny,

    I involved WCF expert to further look at this issue. I am moving your thread into the Windows Communication Foundation, Serialization, and Networking Forum for dedicated support. Thanks for your understanding.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 19, 2014 9:53 AM
  • Hi,

    We should have an app.config file in our VS project. If you don't, you can add one to the project by right clicking the project within the Solution Explorer, then Add, then New Item. From the "Add New Item" screen, you should see "general" among the common items on the left. Double click the first item "Application Configuration File" in the middle screen and you should be good to go.

    From there, you can add your XML tags.

    Typical Format in the app.config looks like this:

     <?xml version="1.0"?>
     <configuration>
        <startup>
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
        </startup>
        <appSettings>
           <add key="HostDomain" value="\\somedatabaseserver\DatabaseUnitTests" />
           <add key="Port1" value="" />
         </appSettings>
     </configuration>

    Depending on how you compile your WCF service (which format), you should get witin your \project\bin\debug directory a .config file with the same name as your executable or DLL.

    Then reading the config file in code is done with something like this:

      Dim confReader As System.Configuration.AppSettingsReader = New System.Configuration.AppSettingsReader
      Domainvalue = confReader.GetValue("HostDomain", GetType(System.String)).ToString()
      Portvalue = confReader.GetValue("Port1", GetType(System.String)).ToString()

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Thursday, March 20, 2014 6:10 AM
    Moderator