【发布时间】:2013-12-27 17:47:08
【问题描述】:
我正在尝试从我的计算机自托管一些 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";
}
}
通过本地机器上的浏览器,我可以发出简单的获取请求并获取
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">SUCCESS</string>
但是,当我输入 http://<service machine's IP>:8090/testing/testmethod 时,我似乎无法从家庭网络上的任何浏览器 ping 此服务。
谁能告诉我我缺少什么配置才能使该服务对本地网络上的其他计算机可见,而无需 DNS 服务器?
【问题讨论】: