I made my method with post like this:
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare)]
List<Human> GetHuman(UserEnteredName humanName);
The UserEnteredName class has just one property – string.
And it works. But, I need to make it to be get, not post.
I tried with this:
[WebInvoke(Method= "GET", UriTemplate = "GetHuman?username={John}",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
But it doesn’t work. What do I need to change?
According to your
UriTemplate, your method would have to look something likeI suspect you are mistakenly putting a possible parameter value in your
UriTemplate. Try something likeAlso, for
GET, you can use theWebGetAttribute, which is slightly cleaner.I would change your method to take a
stringparameter and construct theUserEnteredNameinstance in the method body. It may be possible to use yourUserEnteredNametype as a parameter if it uses theTypeConverterAttribute, but I have never done this, so I can’t say how easy (or not) it is. See the WCF Web HTTP Programming Model Overview, specifically the UriTemplate Query String Parameters and URLs section.