如何建立WCF自托管REST服务? [英] How to set up WCF Self-Hosted REST service?

查看:159
本文介绍了如何建立WCF自托管REST服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的本地网络上试图自主机从我的电脑消费的一些WCF RESTful服务由机器。我有一个WCF没有经验,当谈到这在很大程度上是一个福利局。我创建了一个非常基本的,剥离下来的控制台应用程序,看看我能得到它的工作。

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();
    }

下面是服务代码:

[ServiceContract]
public interface ITestClass
{
     [WebGet]
     [OperationContract]
    string TestMethod();
}

public class TestClass : ITestClass
{
    public string TestMethod()
    {
        return "SUCCESS";
    }
}

这是对我的LOCALMACHINE浏览器,我可以发出简单的GET请求,并得到

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>



不过,我似乎不能够ping通从任何浏览器这个服务我的家庭网络当我在键入http://<服务机的IP>:8090 /测试/ TestMethod的

谁能告诉我我缺少什么样的配置,以使该服务是我的本地网络上的其他计算机上可见,而不需要DNS服务器?

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?

推荐答案

您可能需要使用的netsh 命令来注册端口:

You might need to register the port by using the netsh command:

netsh http add urlacl url=http://+:8090/ user=\Everyone

另外,还要确保您已禁用主持此服务的计算机上的防火墙。否则,有机会,它可能会阻塞交通港口 8090

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.

这篇关于如何建立WCF自托管REST服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆