Click here to Skip to main content
15,885,869 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.

CSS
<pre lang="xml">&lt;configuration&gt;
    &lt;system.servicemodel&gt;
        &lt;bindings&gt;
            &lt;basichttpbinding&gt;
                &lt;binding name="BasicHttpBinding_IBrokerService" closetimeout="00:01:00"&gt;
                    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"
                    useDefaultWebProxy="true"&gt;
                    &lt;readerquotas maxdepth="32" maxstringcontentlength="8192" maxarraylength="16384"&gt;
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt;
                    &lt;security mode="None"&gt;
                        &lt;transport clientcredentialtype="None" proxycredentialtype="None"&gt;
                            realm="" /&gt;
                        &lt;message clientcredentialtype="UserName" algorithmsuite="Default" /&gt;
                    &lt;/transport&gt;&lt;/security&gt;
                &lt;/readerquotas&gt;&lt;/binding&gt;
            &lt;/basichttpbinding&gt;
        &lt;/bindings&gt;
        &lt;client&gt;
            &lt;endpoint address="http://abcd/defgf/test.svc" binding="basicHttpBinding"&gt;
                bindingConfiguration="BasicHttpBinding_ITestService" contract="TestServiceProxy.ITestService"
                name="BasicHttpBinding_ITestService" /&gt;
        &lt;/endpoint&gt;&lt;/client&gt;
    &lt;/system.servicemodel&gt;
&lt;/configuration&gt; </pre>




I need to change the "abcd" in endpoint address with the user specified value through console.
Posted
Updated 19-Jun-14 13:23pm
v4
Comments
[no name] 19-Jun-14 21:05pm    
Advise what? Parse the file. What is the problem with the code that you have written?
mayooran99 19-Jun-14 22:10pm    
The question is how can I change the endpoint address dynamically during run time? that is the abcd part in url need to be changed with a user given input...

1 solution

Hello friend, you may visit the below link:

How to Change .NET Configuration Files at Runtime (including for WCF)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900