无法连接到已部署的Azure云服务
部署Azure云服务后,我无法连接到它。查看类似问题的答案,我尝试检查我的端点,但它们似乎配置正确。我正在尝试通过TCP连接。当我使用Azure Compute Emulator时,一切都在本地运行良好 这是我的.csdef文件:无法连接到已部署的Azure云服务,azure,tcp,Azure,Tcp,部署Azure云服务后,我无法连接到它。查看类似问题的答案,我尝试检查我的端点,但它们似乎配置正确。我正在尝试通过TCP连接。当我使用Azure Compute Emulator时,一切都在本地运行良好 这是我的.csdef文件: <?xml version="1.0" encoding="utf-8"?> <ServiceDefinition name="Server" xmlns="http://schemas.microsoft.com/ServiceHostin
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="Server" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2013-03.2.0">
<WorkerRole name="WorkerRole" vmsize="Small">
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
<Endpoints>
<InputEndpoint name="Endpoint1" protocol="tcp" port="4029"/>
</Endpoints>
<LocalResources>
<LocalStorage name="DiagnosticStore" sizeInMB="20000" cleanOnRoleRecycle="false" />
</LocalResources>
</WorkerRole>
</ServiceDefinition>
最后,在我的客户中,我有以下几点:
var hostName = new HostName("[IP Address as shown in the Azure Management Portal]");
TcpSocket = new StreamSocket();
try
{
await TcpSocket.ConnectAsync(hostName, "4029");
...
}
这段代码运行良好,当我的服务器在Azure emulator中本地运行时,我能够将我的客户端连接到服务器,因此我倾向于认为问题在于我在Azure上设置服务器的方式。有没有其他我应该检查的东西,或者关于如何进一步调试的提示?非常感谢您的帮助 我怀疑问题在于您使用了IPAddress.Loopback和本地端口的选择 由于未在端点的配置中指定本地端口,Windows Azure可能会分配一个随机端口。然后,您应该使用以下方式访问端点:
listener = new TcpListener(
RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].IPEndpoint);
listener.ExclusiveAddressUse = false;
listener.Start();
这段代码来自Maarten Balliauw
您可以选择在服务定义文件中指定本地端口
listener = new TcpListener(
RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].IPEndpoint);
listener.ExclusiveAddressUse = false;
listener.Start();