David 已经回答了大部分问题,详细说明了它为什么起作用:
https://azure.microsoft.com/nl-nl/documentation/articles/cloud-services-role-enable-remote-desktop/
看一下csdef文件,里面有一个imports部分
<Imports>
<Import moduleName="<import-module>"/>
</Imports>
RDP 的模块是“RemoteAccess”,会有一个“RemoteAccessForwarder”,所有插件/模块都在 Azure SDK 的这个目录下(用你的 azure SDK 版本替换 v2.9)
C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins
导入此模块会导致在运行时将以下配置添加到 csdef 文件中:
<?xml version="1.0" ?>
<RoleModule
xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"
namespace="Microsoft.WindowsAzure.Plugins.RemoteAccess">
<Startup priority="-1">
<Task commandLine="RemoteAccessAgent.exe" executionContext="elevated" taskType="background" />
<Task commandLine="RemoteAccessAgent.exe /blockStartup" executionContext="elevated" taskType="simple" />
</Startup>
<ConfigurationSettings>
<Setting name="Enabled" />
<Setting name="AccountUsername" />
<Setting name="AccountEncryptedPassword" />
<Setting name="AccountExpiration" />
</ConfigurationSettings>
<Endpoints>
<InternalEndpoint name="Rdp" protocol="tcp" port="3389" />
</Endpoints>
<Certificates>
<Certificate name="PasswordEncryption" storeLocation="LocalMachine" storeName="My" permissionLevel="elevated" />
</Certificates>
</RoleModule>
这将为 RDP 连接打开端口 3389,因此端点位于 .csdef 文件中,但通过导入。
另外看看“RemoteForwarder”,它作为网关,所以只需要在外面打开1个端口(3389),只有1个实例会监听这个。然后 RemoteForwarder 会将 RDP 连接转发到正确的机器。更多信息:
https://blogs.msdn.microsoft.com/avkashchauhan/2011/12/06/how-does-remote-desktop-works-in-windows-azure/