简体   繁体   English

无法连接到已部署的Azure云服务

[英]Unable to connect to deployed Azure Cloud service

I've been unable to connect to my Azure Cloud service once I deploy it. 部署后,我无法连接到我的Azure云服务。 Looking at the answers to similar questions, I've tried examining my endpoints, but they seem to be configured correctly. 看看类似问题的答案,我已经尝试检查我的端点,但它们似乎配置正确。 I'm trying to connect through TCP. 我正在尝试通过TCP连接。 Everything runs fine locally, when I use the Azure Compute Emulator. 当我使用Azure Compute Emulator时,一切都在本地运行良好。

Here's my .csdef file: 这是我的.csdef文件:

<?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>

On my server instance, which is an Azure worker role, I have the following TCP Listener: 在我的服务器实例(Azure工作者角色)上,我有以下TCP侦听器:

const int port = 4029;
IPAddress addr = IPAddress.Loopback;
try
{
    var listener = new TcpListener(addr, port);
    listener.Start();
    ...
}

And finally, in my client I have the following: 最后,在我的客户端,我有以下内容:

var hostName = new HostName("[IP Address as shown in the Azure Management Portal]");
TcpSocket = new StreamSocket();

try
{
     await TcpSocket.ConnectAsync(hostName, "4029");
     ...
}

This code works fine and I'm able to connect my client to my server when my server is running locally in the Azure emulator, so I'm inclined to think that the problem lies in the way I've set up my server on Azure. 此代码工作正常,当我的服务器在Azure模拟器中本地运行时,我能够将我的客户端连接到我的服务器,所以我倾向于认为问题在于我在Azure上设置服务器的方式。 Are there any additional things I should check for, or tips on how to further debug this? 是否还有其他我需要检查的内容,或者有关如何进一步调试的提示? Any help is greatly appreciated! 任何帮助是极大的赞赏!

I suspect the problem is your use of IPAddress.Loopback and the choice of local port. 我怀疑问题是你使用IPAddress.Loopback和本地端口的选择。

Since you don't specify a local port in the ServiceDefinition configuration for the endpoint Windows Azure could assign a random port. 由于您未在端点的ServiceDefinition配置中指定本地端口,因此Windows Azure可以分配随机端口。 You should then access the endpoint using: 然后,您应使用以下方法访问端点:

listener = new TcpListener( 
    RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].IPEndpoint); 
listener.ExclusiveAddressUse = false; 
listener.Start(); 

This code comes from a Maarten Balliauw post . 此代码来自Maarten Balliauw 帖子

You can optionally specify the local port in the Service Definition file. 您可以选择在服务定义文件中指定本地端口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM