2016-11-30 71 views
0

所以這裏是我的客戶端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>--> 
+0

https://msdn.microsoft.com/en-us/library/ms731862(v=vs.110).aspx 或 http://stackoverflow.com/questions/2943148/how-to-programmatically-connect-a -client-to-a-wcf-service –

+1

我認爲這可能有所幫助: [http://stackoverflow.com/questions/11583882/programatically-adding-an-endpoint](http://stackoverflow.com/questions/11583882/programatically-adding-an-endpoint) –

回答

0

這是我的app.config,我不使用標籤的所有attibutes,但可能它可以幫助你:

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