我正在尝试从我的计算机上自托管一些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(); 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请求并获取
SUCCESS
但是,当我输入时,我似乎无法从家庭网络上的任何浏览器ping此服务http://
.
任何人都可以告诉我,我缺少哪些配置,以使服务对我本地网络上的其他计算机可见,而无需DNS服务器?
在这里你去...我写的博客.
自托管RestService