Вы можете обновить режим безопасности для всех узлов привязки с помощью такого кода. Это будет работать, даже если у вас есть несколько узлов привязки и разные виды узлов привязки (например, wsHttpBinding, basicHttpBinding и т. Д.)
$bindingNodes = $doc.configuration.'system.serviceModel'.bindings
$securityNodes = $bindingNodes.SelectNodes("//security")
foreach($securityNode in $securityNodes)
{
$mode = $securityNode.Attributes['mode'].Value;
Write-Host("Mode = ", $mode)
# I am checking for none in a case insensitive way here, so only none will be changed to transport. You can remove the if condition, in case you want any value to change to Transport.
if($mode -ieq 'none') {
$securityNode.Attributes['mode'].Value = 'Transport'
}
}
Я дал только важную часть выше для вашего понимания.
Общий код функции изменится на что-то вроде этого.
function Update-ServiceConfigFile() {
Write-Verbose "Updating Service Web Config"
$webConfig = 'directoryToConfigInAzure/web.config'
Write-Verbose -Message "Downloading $webConfig"
$tempFile = [IO.Path]::GetTempFileName()
Write-Verbose "Write $tempFile"
Download-File $accessToken $webappName $webConfig $tempFile
$doc = [xml](Get-Content $tempFile)
$customerId = $WebAppName.Substring(0, 6)
$nodes = $doc.configuration.'system.serviceModel'.client.endpoint
foreach($node in $nodes) {
$address = $node.Attributes['address'].Value;
$address = $address -replace ':ServicePortNumber', ''
$ub = [System.UriBuilder]::new($address);
if($Insecure) {
Write-Verbose "Setting HTTP (insecure) API endpoint"
$ub.Scheme = 'http';
} else {
Write-Verbose "Setting HTTPS (secure) API endpoint"
$ub.Scheme = 'https';
}
if($address.contains("SomeAddress"))
{
$ub.Host = "service-prod-$($customerId).ourdomainname.cloud"
}else{
$ub.Host = "service-$($customerId).ourdomnaineame.cloud";
}
if($webAppName -like '*-test') {
$ub.Host = "service-test-$($customerId).ourdomnaineame.cloud";
}
$ub.Port = -1;
$node.Attributes['address'].Value = $ub.Uri.AbsoluteUri;
}
# NEW CODE STARTS HERE
$bindingNodes = $doc.configuration.'system.serviceModel'.bindings
$securityNodes = $bindingNodes.SelectNodes("//security")
foreach($securityNode in $securityNodes)
{
$mode = $securityNode.Attributes['mode'].Value;
Write-Host("Mode = ", $mode)
# I am checking for none in a case insensitive way here, so only none will be changed to transport. You can remove the if condition, in case you want any value to change to Transport.
if($mode -ieq 'none') {
$securityNode.Attributes['mode'].Value = 'Transport'
}
}
# NEW CODE ENDS HERE
$doc.Save($tempFile)
Upload-File $accessToken $webappName $webConfig $tempFile
Remove-Item $tempFile -Force
}