我正在尝试使两个应用程序使用HTTP / WCF通过本地网络进行通信。主服务器发出Web请求,并寻找每个都运行Web服务的Slave应用程序。从站被配置为响应localhost:\\[MACHINENAME]:8000
当我在与主服务器相同的计算机上运行从服务器时,它起作用,但是当我在同一网络中的另一台计算机上运行它时,它不起作用。我通过cmd提示符Ping [MachineName]确认计算机在同一网络上。将请求发送到同一网络上的另一台计算机需要什么?
从站设置Web服务:
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防火墙(默认情况下处于启用状态)将对其进行阻止。
您将需要向防火墙添加例外,以允许该端口上的流量路由到您的应用程序。
单击“开始”,然后键入“具有高级安全性的Windows防火墙”。
单击“入站规则”->“新建规则”,然后根据需要添加“程序”规则或“端口”规则。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句