找不到服务端点?

G G*_* Gr 4 .net c# rest wcf

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

如果我尝试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();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

服务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);
        }
Run Code Online (Sandbox Code Playgroud)

IService1:

[ServiceContract]
public interface IService1
{
    [WebGet(UriTemplate = "/{value}")]
    string GetData(string value);
Run Code Online (Sandbox Code Playgroud)

Jus*_*ony 6

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

[WebGet(UriTemplate = "{value}")]
[OperationContract]
Run Code Online (Sandbox Code Playgroud)

基本URL将使用尾部斜杠,因此您实际上正在寻找http://localhost:8000/hello//help当前代码