Reputation: 10713
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?
Upvotes: 0
Views: 165
Reputation: 57793
According to your UriTemplate
, your method would have to look something like
Human GetHuman(string John)
I suspect you are mistakenly putting a possible parameter value in your UriTemplate
. Try something like
[WebInvoke(Method= "GET", UriTemplate = "GetHuman?username={userName}",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
Human GetHuman(string userName)
Also, for GET
, you can use the WebGetAttribute
, which is slightly cleaner.
I would change your method to take a string
parameter and construct the UserEnteredName
instance in the method body. It may be possible to use your UserEnteredName
type as a parameter if it uses the TypeConverterAttribute
, 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.
Upvotes: 1