【发布时间】:2016-07-11 11:55:50
【问题描述】:
我正在尝试让两个应用程序使用 HTTP / WCF 通过本地网络进行通信。 Master 发出 Web 请求并查找每个运行 Web 服务的 Slave 应用程序。从站配置为回复localhost:\\[MACHINENAME]:8000
当我在与主服务器相同的计算机上运行从服务器时,它可以工作,但当我在同一网络上的另一台计算机上运行它时就不行。我通过 cmd 提示 Ping [MachineName] 确认计算机在同一网络上。向同一网络上的另一台计算机发送请求需要什么?
Slave 设置 webservice:
public void Run()
{
Config config = Config.validateAndCreate();
string machineName = System.Environment.MachineName;
string baseAddress = "http://" + machineName + ":" + config.port;
Service.setConfig(config);
if (new Service().UpdateScripts().status != ExecStatus.OK)
{
throw new Exception("Failed to update scripts");
}
using (WebServiceHost host = new WebServiceHost(typeof(Service), new Uri(baseAddress)))
{
host.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true });
host.Description.Behaviors.Find<ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true;
host.Description.Behaviors.Find<ServiceDebugBehavior>().HttpHelpPageEnabled = false;
ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), "");
host.Open();
log.Info("Service is running at: " + baseAddress);
log.Info("Press the 'q' key to quit...");
while (Console.ReadKey(true).Key != ConsoleKey.Q) { }
host.Close();
}
}
【问题讨论】:
-
您是否有防火墙(例如内置的 Windows 防火墙)正在运行?这是最有可能阻止它的事情。
-
我会检查的!有什么方法可以判断防火墙是否阻塞?
-
如果您使用的是 http,最简单的检查是使用网络浏览器。
-
好的!在这种情况下我应该期待什么?
-
我已将 Master 和 Slave 添加到允许通过防火墙列表中。我仍然没有通过应用程序或浏览器获得任何通信。当我尝试在同一台计算机上使用从属服务器的地址时,确实找不到服务端点 Endpoint。所以我猜奴隶工作。它只是无法访问它的另一台计算机上的主人。同一台电脑上只有master。