How to invoke RESTful WCF service method with multiple parameters?
Posted
by
Scythe
on Stack Overflow
See other posts from Stack Overflow
or by Scythe
Published on 2011-01-04T18:51:25Z
Indexed on
2011/01/04
18:53 UTC
Read the original article
Hit count: 172
I have a RESTful WCF service with a method declared like this:
[OperationContract(Name = "IncrementAge")]
[WebInvoke(UriTemplate = "/", Method = "POST", ResponseFormat = WebMessageFormat.Json)]
Person IncrementAge(Person p);
Here's the implementation:
public Person IncrementAge(Person p)
{
p.age++;
return p;
}
So it takes the Person complex type, increments the age property by one, and spits it back, using JSON serialization. I can test the thing by sending a POST message to the service like this:
POST http://localhost:3602/RestService.svc/ HTTP/1.1
Host: localhost:3602
User-Agent: Fiddler
Content-Type: application/json
Content-Length: 51
{"age":25,"firstName":"Hejhaj","surName":"Csuhaj"}
This works. What if I'd like to have a method like this?
Person IncrementAge(Person p, int amount);
So it'd have multiple parameters. How should I construct the POST message for this to work? Is this possible?
Thanks
© Stack Overflow or respective owner