2010-07-12 83 views
1

我有一個包含'GET'和'POST'操作的簡單WCF合約。我有本地主機上運行的服務。我可以在我的瀏覽器中輸入服務地址並查看服務響應值。當我嘗試從C#代碼執行相同的操作時,出現錯誤「There was no endpoint listening at ....」消息。然而,我可以在代碼中調用服務的'POST'方法。無法在WCF服務上執行'GET'

我錯過了什麼?下面是我的合同代碼

using System; 
using System.ServiceModel; 
using System.ServiceModel.Web; 

namespace WebServiceTest.Services 
{ 
    [ServiceContract] 
    public interface ITestOne 
    { 
     [OperationContract] 
     [WebInvoke(
      Method = "GET", 
      ResponseFormat = WebMessageFormat.Json, 
      BodyStyle = WebMessageBodyStyle.Wrapped, 
      UriTemplate = "GetGreeting/{text1}/{text2}")] 
     string HelloWorld(string text1, string text2); 

     [OperationContract] 
     [WebInvoke(
      Method = "GET", 
      ResponseFormat = WebMessageFormat.Json, 
      BodyStyle = WebMessageBodyStyle.Wrapped, 
      UriTemplate = "Greet/{text1}")] 
     string HelloWorld2(string text1); 

     [OperationContract] 
     [WebInvoke(
      Method="GET", 
      ResponseFormat = WebMessageFormat.Json, 
      BodyStyle = WebMessageBodyStyle.Wrapped, 
      UriTemplate = "Add/{value1}/{value2}")] 
     int Add(string value1, string value2); 

     [OperationContract] 
     [WebInvoke(Method = "POST", 
        ResponseFormat = WebMessageFormat.Json, 
        BodyStyle = WebMessageBodyStyle.Wrapped)] 
     String GetAllSpecies(); 

     [OperationContract] 
     [WebInvoke(
      Method = "GET", 
      ResponseFormat = WebMessageFormat.Json, 
      BodyStyle = WebMessageBodyStyle.Wrapped, 
      UriTemplate = "specie")] 
     String GetAllSpecies2(); 

} 

}

回答

1

我找到了答案。問題在於該服務正在使用ITestOne服務合同,而客戶端正在使用爲ITestOne生成的代理客戶端(通過MEX端點獲取)。生成的代理不包含服務合同包含的[WebGet]屬性。