我运行了一个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以允许从本地端口隧道传输到外部世界方面,我是否遗漏了一些内容?
答案 0 :(得分:4)
噢,天哪,它的记录很少,但我必须在我的VM上的Windows防火墙的端口添加规则。
开始 - &gt;具有高级安全性的Windows防火墙 - &gt;右键单击入站规则 - &gt;添加规则...为您在Azure管理门户(在线门户网站)的“端点”部分中指定的端口创建新的端口规则...