title: MSDeploy to Azure Web App: Could not connect to the remote computer using the specified process ("Web Management Service")
body: <p>We publish to our Azure Web App using MSBuild MSDeploy in VSO/VSTS Build (vNext) using the script below. This works well.</p>
  
  <p>BUT, when assigning the Azure Web App to a custom domain (through the Azure Portal), the publish fails.</p>
  
  <p><strong>VSTS Build error on MSDeploy:</strong></p>
  
  <blockquote>
    <p>Publishing with publish method [MSDeploy]
    Executing command ["C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:IisApp='C:\a\8b0700fff\MrProjectMain\Api\wwwroot' -dest:IisApp='myproject-prod-webapp',ComputerName='<a href="https://myproject-prod-webapp.azurewebsites.net/msdeploy.axd" rel="nofollow noreferrer">https://myproject-prod-webapp.azurewebsites.net/msdeploy.axd</a>',UserName='$myproject-prod-webapp',Password='{PASSWORD-REMOVED-FROM-LOG}',IncludeAcls='False',AuthType='Basic' -verb:sync -enableLink:contentLibExtension  -retryAttempts:2 -disablerule:BackupRule]<br>
    [error]Error Code: ERROR_COULD_NOT_CONNECT_TO_REMOTESVC<br>
    [error]More Information: Could not connect to the remote computer ("myproject-prod-webapp.azurewebsites.net") using the specified process ("Web Management Service") because the server did not respond. Make sure that the process ("Web Management Service") is started on the remote computer.  Learn more at: <a href="http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_COULD_NOT_CONNECT_TO_REMOTESVC" rel="nofollow noreferrer">http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_COULD_NOT_CONNECT_TO_REMOTESVC</a>.
    [error]Error: The remote server returned an error: (403) Forbidden.<br>
    [error]Error count: 1.</p>
  </blockquote>
  
  <p><strong>Azure portal custom domain setup:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/hlO9g.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hlO9g.png" alt="Azure Portal Custom domain"></a></p>
  
  <p><strong>Publish script:</strong></p>
  
  <pre><code>param($websiteName, $packOutput)
  
  $website = Get-AzureWebsite -Name $websiteName
  $msdeployurl = $website.EnabledHostNames[1]
  
  $publishProperties = @{'WebPublishMethod'='MSDeploy';
                          'MSDeployServiceUrl'=$msdeployurl;
                          'DeployIisAppPath'=$website.Name;
                          'Username'=$website.PublishingUsername;
                          'Password'=$website.PublishingPassword;
                          'SkipExtraFilesOnServer'='False';
                          'AllowUntrustedCertificate'='True'}
  
  Write-Output "Publishing web app..."
  $publishScript = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\default-publish.ps1"
  . $publishScript -publishProperties $publishProperties  -packOutput $packOutput
  </code></pre>