2010-07-12 138 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]属性。