【问题标题】:Can't open TCP channel on Azure Virtual Machine无法在 Azure 虚拟机上打开 TCP 通道
【发布时间】:2014-06-14 18:55:33
【问题描述】:

我正在运行一个 Azure 虚拟机,并且在我编写的 Windows 服务中具有以下逻辑,该服务还托管一个带有 MEX HTTP 端点的 WCF TCP 端点:

    private void OpenTCPChannel()
    {
        string fqdn = System.Net.Dns.GetHostEntry("localhost").HostName;
        NetTcpBinding binding = new NetTcpBinding(SecurityMode.None, true);
        binding.SendTimeout = new TimeSpan(0, 1, 0);
        binding.ReceiveTimeout = new TimeSpan(0, 1, 0);
        binding.MaxReceivedMessageSize = int.MaxValue;
        binding.MaxConnections = int.MaxValue;
        binding.ListenBacklog = int.MaxValue;
        binding.ReliableSession.Enabled = true;
        binding.ReliableSession.Ordered = true;
        binding.ReliableSession.InactivityTimeout = new TimeSpan(0, 1, 0);
        Uri serviceAddress = new Uri(String.Format("net.tcp://{0}:{1}/GameServer", fqdn, Properties.Settings.Default["GameServerPort"]));
        ServiceHost serviceHost = new ServiceHost(service, serviceAddress);
        serviceHost.AddServiceEndpoint(typeof(IGameService), binding, serviceAddress);
        ServiceMetadataBehavior metadataExchange = new ServiceMetadataBehavior();
        metadataExchange.HttpGetEnabled = true;
        metadataExchange.HttpGetUrl = new Uri(string.Format("http://{0}:{1}/GameServer", fqdn, Properties.Settings.Default["MEXPort"]));
        serviceHost.Description.Behaviors.Add(metadataExchange);
        serviceHost.Open();
        log.WriteEntry(String.Format("Successfully started TCP endpoint at {0}.", serviceAddress.ToString()));
        log.WriteEntry(String.Format("Successfully started MEX endpoint at {0}.", metadataExchange.HttpGetUrl.ToString()));
    }

当我在本地测试时,代码运行得非常好,但是当我在 Azure VM 上运行我的服务并打开我的 TCP 通道时,由于某种原因我无法访问我的 MEX 端点。

我将尝试导航到:http://<MyServiceName>.cloudapp.net:<MEXPort>/GameServer,但我无法从该地址获取服务引用。在如何配置 Azure VM 以允许从本地端口到外部世界的隧道传输方面,我是否遗漏了什么?

【问题讨论】:

    标签: c# wcf azure tcp virtual-machine


    【解决方案1】:

    天哪,文档记录太差了,但我不得不在我的 VM 上的 Windows 防火墙中的端口中添加规则。

    开始 -> 具有高级安全性的 Windows 防火墙 -> 右键单击​​入站规则 -> 添加规则...为您在 Azure 管理门户(在线门户)...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      相关资源
      最近更新 更多