0

So here's my App.config from the client side, but I need to do this with C# code, so can anybody help me? I've tried some ways to do that but still I could not find out how.

<!--<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IInfo" />
      </basicHttpBinding>
   </bindings>
    <client>
      <endpoint address="http://appserver.gwp.ge/CustomerService/Info.svc"
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IInfo"
      contract="BillingService.IInfo" name="BasicHttpBinding_IInfo" />
    </client>
  </system.serviceModel>
</configuration>-->
  • https://msdn.microsoft.com/en-us/library/ms731862(v=vs.110).aspx or http://stackoverflow.com/questions/2943148/how-to-programmatically-connect-a-client-to-a-wcf-service – Narek Arzumanyan Nov 30 '16 at 07:32
  • 1
    I think this may help: [http://stackoverflow.com/questions/11583882/programatically-adding-an-endpoint](http://stackoverflow.com/questions/11583882/programatically-adding-an-endpoint) – Hung Nguyen Nov 30 '16 at 07:34

1 Answers1

0

This is my app.config, I don't use all the attibutes of the tags, but may it helps you:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <connectionStrings>
        <!-- Example connection to a SQL Server Database on localhost. -->
        <add name="MYCONFIG"
            connectionString="Data Source=.;Initial Catalog=DBName;Integrated Security=True">
        </add>
    </connectionStrings>
    <appSettings>
        <!-- access these values via the property:
            System.Configuration.ConfigurationManager.AppSettings[key]
        -->
        <add key="user" value="myself" />
        <add key="rememberUser" value="false"/>
    </appSettings>
</configuration>

How to access it:

Configuration configFile= ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
//get value
String s = configFile.AppSettings.Settings["user"].Value;
//set value
configFile.AppSettings.Settings["rememberUser"].Value = "true";
//save
configFile.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
tec
  • 999
  • 3
  • 18
  • 40