Modify user in app.config

0

I have a dll where user and password are passed through the app.config to the webservice and I would like to see how to do this so that instead of passing a hardcode a variable is passed which can then be reported to the dll in time execution. Would this be possible? I am not very expert in c # the truth that is why it is costing me but I manage two possible scenarios:

  • include a key that can be modified in the future from the program
  • the program directly modifies the value of the wsse:username and the password
  • But I am not able to implement any of the two options and make them work.

    The app.config would be something like this:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <add key="XXXXXX" value="XXXXXXX" />
        <add key="XXXXX" value="xxxxxx" />
      </appSettings>
      <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="e3s-xxxx">
              <security mode="Transport" />
            </binding>
            <binding name="e3sxxxx">
              <security mode="Transport" />
            </binding>
          </basicHttpBinding>
        </bindings>
        <client>
          <endpoint address="https://xxxxx:443/ctxweb/secured_ssl/xxxx_waste"
            binding="basicHttpBinding" bindingConfiguration="e3s-xxxx"
            contract="E3S_XXXX.Ie3xxxx" name="e3s-xxxx" >
             <headers>
              <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
                <wsse:UsernameToken>
                  <wsse:Username>miusuario</wsse:Username>
                  <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">miprueba</wsse:Password>
                </wsse:UsernameToken>
              </wsse:Security>
            </headers>
          </endpoint>
    

    Thank you very much everyone for your help.

        
    asked by xucosp 21.03.2018 в 16:16
    source

    1 answer

    0

    For your first scenario I think it could help you, in my case, I have a key in the app.config that tells me which server I want to connect to:

    <appSettings>
      <add key="server_al_que_me_conecto" value="y"/>
    </appSettings>
    

    That key has different values and in my connection DLL I get the value of the key and this, depending on the value, connects against one server or another (that is, I could change the value of the key and change where the application is connected at runtime).

    I get the value of the key so that:

       string contra_quien_estoy_conectando = System.Configuration.ConfigurationManager.AppSettings.Get("server_al_que_me_conecto")[0].ToString();
    

    In your case, in addition, you want to change the value of the key of the app.config in runtime and, although it is not my case, looking for a bit I have found this that you may be worth to change those values:

    Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath); 
    config.AppSettings.Settings["Key"].Value="Value";
    config.Save(ConfigurationSaveMode.Modified);
    

    Try this info and I hope it will be helpful. Good luck!

        
    answered by 21.03.2018 в 16:43