Unable to do a 'GET' on WCF Service
I have a simple WCF contract that contains both 'GET' and 'POST' operations. I have the service running on localhost. I am able to type the service address into my browser and see the service response values. When I try to do the same thing from C# code, I get the error "There was no endpoint li开发者_开发知识库stening at...." message. I can however call a 'POST' method on the service from in code.
What am I missing? Below is my Contract code
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();
}
}
I found the answer. The problem was that the service was using the service contract ITestOne and the client was using the generated proxy client for ITestOne (obtained through MEX endpoint). The generated proxy did not contain the [WebGet] attribute that the service contract contained.
精彩评论