I'm trying to self-host some WCF RESTful services from my computer for consumption by machines on my local network. I have no experience with WCF and am largely a newb when it comes to this. 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
<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
.
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?
This is referred to as a self hosting WCF service, the exact meaning of Self Hosted is that it hosts the service in an application that could be a Console Application or Windows Forms and so on. Earlier we saw what a WCF Service is in the . Net environment. We can host a WCF service in IIS and a Windows service also.
By default, Windows Communication Foundation (WCF) makes endpoints available only to SOAP clients.
here you go .. a blog written by me.
Self Hosted RestService
You might need to register the port by using the netsh
command:
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With