[英]How to set up WCF Self-Hosted REST service?
I'm trying to self-host some WCF RESTful services from my computer for consumption by machines on my local network. 我正在尝试从我的计算机上自托管一些WCF RESTful服务,供本地网络上的计算机使用。 I have no experience with WCF and am largely a newb when it comes to this. 我没有WCF的经验,在这方面我很大程度上是一个新手。 I created a very basic, stripped down console app to see if I could get it working. 我创建了一个非常基本的,剥离的控制台应用程序,看看我是否能让它运行起来。
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();
}
Here's the service code: 这是服务代码:
[ServiceContract]
public interface ITestClass
{
[WebGet]
[OperationContract]
string TestMethod();
}
public class TestClass : ITestClass
{
public string TestMethod()
{
return "SUCCESS";
}
}
From a browser on my localmachine, I'm able to issue a simple get request and get 从我本地机器上的浏览器,我可以发出一个简单的get请求并获取
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">SUCCESS</string>
However, I don't seem to be able to ping this service from any browsers on my home network when I type in http://<service machine's IP>:8090/testing/testmethod
. 但是,当我输入http://<service machine's IP>:8090/testing/testmethod
时,我似乎无法从家庭网络上的任何浏览器ping此服务。
Can anyone tell me what configuration I'm missing to enable the service to be visible to other machines on my local network without needing a DNS server? 任何人都可以告诉我,我缺少哪些配置,以使服务对我本地网络上的其他计算机可见,而无需DNS服务器?
here you go .. a blog written by me. 在这里你去...我写的博客。
You might need to register the port by using the netsh
command: 您可能需要使用netsh
命令注册该端口:
netsh http add urlacl url=http://+:8090/ user=\Everyone
Also make sure that you have disabled the firewall on the computer hosting this service. 还要确保已在托管此服务的计算机上禁用防火墙。 Otherwise, chances are that it might be blocking the traffic to port 8090
. 否则,可能会阻止到8090
端口的流量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.