我正在尝试在我的电脑上自行托管一些WCF RESTful服务,供本地网络上的机器使用。我对WCF毫无经验,在这方面基本上是个新手。我创建了一个非常基本、简化的控制台应用程序,以查看是否可以使其正常工作。
static void Main(string[] args)
{
Uri httpUrl = new Uri("http://localhost:8090/");
var host = new WebServiceHost(typeof(TestClass), httpUrl);
var binding = new WebHttpBinding(); // NetTcpBinding();
host.AddServiceEndpoint(typeof(ITestClass), binding, "testing");
ServiceDebugBehavior stp = host.Description.Behaviors.Find<ServiceDebugBehavior>();
stp.HttpHelpPageEnabled = false;
host.Open();
Console.WriteLine("Commence with the testing!");
Console.ReadLine();
host.Close();
}
这是服务的代码:
[ServiceContract]
public interface ITestClass
{
[WebGet]
[OperationContract]
string TestMethod();
}
public class TestClass : ITestClass
{
public string TestMethod()
{
return "SUCCESS";
}
}
我可以在本地浏览器上发出简单的get请求并获取到响应。
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">SUCCESS</string>
然而,当我在家庭网络中的任何浏览器中输入http://<服务机器的IP>:8090/testing/testmethod
时,似乎无法ping通该服务。
有人可以告诉我缺少哪些配置以使得服务对本地网络中的其他计算机可见,而不需要DNS服务器吗?