WCF Endpoint variable Replacement

Regarding this post: http://help.octopusdeploy.com/discussions/questions/4-wcf-endpoint-url-replacement

Was there ever a solution implemented for this?

Hi Eli,

No, the item is on our todo list:

https://trello.com/card/wcf-endpoint-replacement/4e907de70880ba000079b75c/31

For now using Deploy.ps1 or a config transform is the best way to go.

Paul

Thanks Paul
We have created the below scripts to perform the changes in PreDeploy.ps1

get the directory of this script file

$currentDirectory = (get-item $MyInvocation.MyCommand.Path).parent.FullName

get the full path and file name of the App.config file in the same directory as this script

$appConfigFile = [IO.Path]::Combine($currentDirectory, ‘MyApp.Service.exe.config’)
#Service Name
$wcfServiceName = “MyApp.WcfService.SheetDefinitions”
#new Base Name
$wcfBaseAddress = “http://localhost/myservice

initialize the xml object

$appConfig = New-Object XML

load the config file as an xml object

$appConfig.Load($appConfigFile)

write-host "Loaded config file: " + $appConfigFile

foreach( $service in $appConfig.configuration.“system.serviceModel”.services.service)
{
write-host $service.name
if ($service.name -eq $wcfServiceName)
{
write-host “Changing base addresses for service '” + $service.name + "’"
foreach($baseAddress in $service.host.baseAddresses.add)
{
write-host "Changing base address from " + $baseAddress.baseAddress + " to " + $wcfBaseAddress
$baseAddress.baseAddress = $wcfBaseAddress
}
}
}

save the updated config file

$appConfig.Save($appConfigFile)

So I have a solution for endpoints. For each endpoint name I have a variable in Octopus (put in using the REST API).

I then run this c# script to alter the file at run time.

var xdoc = new System.Xml.XmlDocument();
string file = Octopus.Parameters[“Octopus.Action[Install Admin Portal].Output.Package.InstallationDirectoryPath”] + “\config\clients.config”;
Console.WriteLine(file);
xdoc.Load(file);

foreach (System.Xml.XmlNode xElement in xdoc.ChildNodes){
Console.WriteLine(xElement.Name);
if (xElement.Name.Equals(“client”)){
foreach (System.Xml.XmlNode endpoints in xElement.ChildNodes){
Console.WriteLine(endpoints.Name);
if (endpoints.Attributes != null){
Console.WriteLine(“T1”);

            string name = endpoints.Attributes["name"].Value;
            Console.WriteLine(name);
            string address = Octopus.Parameters[name];
            Console.WriteLine(address);
            endpoints.Attributes["address"].Value = address;
        }
    }
}

}
xdoc.Save(file);