app.config中的c#端点



所以这是我的 App.config从客户端端,但是我需要用C#代码执行此操作,所以有人可以帮助我吗?我已经尝试了一些方法来做到这一点,但我仍然找不到。

<!--<?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>-->

这是我的应用程序。

<?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>

如何访问它:

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");

相关内容

  • 没有找到相关文章

最新更新