You can do it like this:
For example , i want to modify my service endpoint address at runtime so i have the following ServiceEndpoint.xml file.
<?xml version="1.0" encoding="utf-8" ?>
<Services>
<Service name="FileTransferService">
<Endpoints>
<Endpoint name="ep1" address="http://localhost:8080/FileTransferService.svc" />
</Endpoints>
</Service>
</Services>
For reading your xml :
var doc = new XmlDocument();
doc.Load(FileTransferConstants.Constants.SERVICE_ENDPOINTS_XMLPATH);
XmlNodeList endPoints = doc.SelectNodes("/Services/Service/Endpoints");
foreach (XmlNode endPoint in endPoints)
{
foreach (XmlNode child in endPoint)
{
if (child.Attributes["name"].Value.Equals("ep1"))
{
var adressAttribute = child.Attributes["address"];
if (!ReferenceEquals(null, adressAttribute))
{
address = adressAttribute.Value;
}
}
}
}
Then get your web.config file of your client at runtime and assign the service endpoint address as:
Configuration wConfig = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap { ExeConfigFilename = @"C:\FileTransferWebsite\web.config" }, ConfigurationUserLevel.None);
ServiceModelSectionGroup wServiceSection = ServiceModelSectionGroup.GetSectionGroup(wConfig);
ClientSection wClientSection = wServiceSection.Client;
wClientSection.Endpoints[0].Address = new Uri(address);
wConfig.Save();