How can I change the endpoint address in app.config with the console input? RRS feed

  • Question

  • I have an app which has a service reference. I need to change the URL of the endpoint address in app.config file based on the console input from user. How do I do this through C#? Please advice.
                    <binding name="BasicHttpBinding_IBrokerService" closeTimeout="00:01:00"
                        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                        maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                        <security mode="None">
                            <transport clientCredentialType="None" proxyCredentialType="None"
                                realm="" />
                            <message clientCredentialType="UserName" algorithmSuite="Default" />
                <endpoint address="http://abcd/defgf/test.svc" binding="basicHttpBinding"
                    bindingConfiguration="BasicHttpBinding_ITestService" contract="TestServiceProxy.ITestService"
                    name="BasicHttpBinding_ITestService" />
    I need to change the "abcd" in endpoint address with the user specified value through console.


    Thursday, June 19, 2014 9:52 AM


All replies

  • Hi Mayooran,

    See how to modify app.config at runtime from the following link.

    Hope useful.


    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.

    • Marked as answer by Mayooran99 Friday, June 20, 2014 2:48 AM
    Friday, June 20, 2014 1:51 AM
  • I managed to do it this way:

     static void UpdateAppConfig(String Name)
                var doc = new XmlDocument();
                XmlNodeList endpoints = doc.GetElementsByTagName("endpoint");
                foreach (XmlNode item in endpoints)
                    var addressAttribute = item.Attributes["address"];
                    if (!ReferenceEquals(null, addressAttribute))
                        addressAttribute.Value = "http://" + Name + "/defgf/test.svc";


    • Edited by Mayooran99 Friday, June 20, 2014 2:50 AM
    • Marked as answer by Mayooran99 Friday, June 20, 2014 2:50 AM
    Friday, June 20, 2014 2:49 AM
  • There is a small problem. Though the endpoint address I changed has changed, the WCF service doesn't use that address. It is using the default address. Why is that?


    Friday, June 20, 2014 3:02 AM