1

I want to update web reference Url in web.config applicationSettings at runtime

Here is web config application settings

<applicationSettings>
<ItineraryBuilder.Properties.Settings>
  <setting name="ItineraryBuilder_SchedulesConnectionsService_SchedulesConnectionsService"
    serializeAs="String">
    <value>http://www.pathfinder-xml.com/soap/*/services/SchedulesConnections</value>
  </setting>
  <setting name="ItineraryBuilder_SalesForceService_SforceService"
    serializeAs="String">
    <value>https://login.salesforce.com/services/Soap/c/25.0/0DFd00000000Wa6</value>
  </setting>
  <setting name="ItineraryBuilder_OAGService_CBWSPublicService"
    serializeAs="String">
    <value>http://ondemand.oag.com:80/CBWebServicePublic/CBWSPubliclPort</value>
  </setting>
</ItineraryBuilder.Properties.Settings>
</applicationSettings>

here is my code using to update

var configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
var section = (System.Configuration.ClientSettingsSection)configuration.GetSection("applicationSettings/ItineraryBuilder.Properties.Settings");

System.Configuration.SettingValueElement sv = new System.Configuration.SettingValueElement();
sv.Equals("https://test.salesforce.com/services/Soap/c/25.0/0DFd00000000Wa6");
section.Settings.Get("ItineraryBuilder_SalesForceService_SforceService").Value = sv;
configuration.Save();

But it does not update Value, instead remove Value tag from settings

Earlier i was trying to update Web service url, but did not work so i follow this approach, will you please guide me on how to update web service url?

this is what i was doing

SforceService sf = new SforceService();
sf.Url = "test.salesforce.com/services/Soap/c/25.0/0DFd00000000Wa6";;

Please help.

9
  • sv is empty. This line sv.Equals("https://test.salesforce.com/services/Soap/c/25.0/0DFd00000000Wa6"); doesn't do anything. Commented Aug 30, 2012 at 7:54
  • so will you please tell me how to set it? i tired this section.Settings.Get("ItineraryBuilder_SalesForceService_SforceService").Value.ValueXml.InnerText = "test.salesforce.com/services/Soap/c/25.0/0DFd00000000Wa6"; did not work either Commented Aug 30, 2012 at 8:13
  • @tomfanning is right. Don't do this, but when you want to invoke the web service change the url of the instance. Commented Aug 30, 2012 at 8:15
  • i was trying that too , but did not work so is follow this approach, will you please guide me on how to update web service url? this is what i was doing SforceService sf = new SforceService(); sf.Url = "test.salesforce.com/services/Soap/c/25.0/0DFd00000000Wa6"; Commented Aug 30, 2012 at 8:32
  • Edit your question with this code also. Commented Aug 30, 2012 at 8:38

2 Answers 2

2

Don't do this.

Specifically, one would hope that your web application root folder isn't writeable by the application pool identity.

Sign up to request clarification or add additional context in comments.

Comments

1

Thanks Amiram Korach for all you help

With his help i got what i was doing wrong.

As he suggested there is no need to update web config as it is not a good approach and so the solution for the above problem is updating Web reference at runtime and so the following code works fine

SforceService sf = new SforceService();
sf.Url = "test.salesforce.com/services/Soap/c/25.0/0DFd00000000Wa6"

what i was doing wrong, the "sf" was not passed to API class which is used in creating connection. Amiram Korach helped me finding this issue.

Thanks again.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.