2012-03-25 82 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