繁体   English   中英

找不到服务端点?

[英]Service endpoint not found?

在尝试从我的服务中获取时,似乎遇到了未找到服务端点的问题。

如果我尝试http:// localhost:8000 / hello / help我应该看到<string>You entered help <string>但我只获得了无端点? 我根本没有触及我的配置文件,我只是从一个控制台应用程序托管。

主办:

namespace Host
{
    class Program
    {
        static void Main(string[] args)
        {
            WebHttpBinding binding = new WebHttpBinding();
            WebServiceHost host =
            new WebServiceHost(typeof(Service1));
            host.AddServiceEndpoint(typeof(IService1),
            binding,
            "http://localhost:8000/hello");
            host.Open();
            Console.WriteLine("Hello world service");
            Console.WriteLine("Press <RETURN> to end service");
            Console.ReadLine();
        }
    }
}

服务1:

namespace WcfServiceLibrary1
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
    public class Service1 : IService1
    {
        public string GetData(string value)
        {
            return string.Format("You entered: {0}", value);
        }

IService1:

[ServiceContract]
public interface IService1
{
    [WebGet(UriTemplate = "/{value}")]
    string GetData(string value);

从{value}中删除/并确保它被列为OperationContract 它应该是:

[WebGet(UriTemplate = "{value}")]
[OperationContract]

基本URL将带有尾部斜杠,所以你真的在当前代码中寻找http://localhost:8000/hello//help

在黑暗中刺伤...默认情况下,不允许任意进程侦听网络端口。

安装IIS时,将为运行IIS的帐户授予权限 - 如果您希望其他帐户(控制台应用程序,Windows服务)运行的其他应用程序能够侦听端口,则需要授予该权限。

查看netsh add urlacl命令作为起点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM