【发布时间】: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