2012-03-25 85 views
4

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

如果我尝试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); 

回答

6

的/从{}值删除,并确保它被列为OperationContract。它应该是:

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

基本URL会通过与结尾的斜线,所以你真的在当前代码寻找http://localhost:8000/hello//help

+0

嗨Justin很高兴再次见到你,/ {value}是因为我的网址是:http:// localhost:8000/hello没有结束斜线/我认为它可以是或可以不管是否取走它都不能解决问题。 – 2012-03-25 22:00:28

+0

@Garrith我已经更新了我的答案,我注意到你也缺少OperationContractAttribute。 – 2012-03-25 22:08:07

+0

哈哈操作合同失踪! +1 – 2012-03-25 22:09:55

0

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

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

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

+0

但我的vs2010在管理员下运行? – 2012-03-25 22:06:11

+0

作为管理员并不意味着您拥有所有权限 - 只是您有权力授予他们自己。我最近正在开发一个自带托管WCF服务的Windows服务(以允许即时重新配置) - 我的服务无法访问,直到我使用netsh授予许可。我当时正在使用在Windows Server 2008 R2上运行的VS2010。 – Bevan 2012-03-25 22:17:08