【发布时间】:2011-01-04 18:51:25
【问题描述】:
我有一个 RESTful WCF 服务,其方法声明如下:
[OperationContract(Name = "IncrementAge")]
[WebInvoke(UriTemplate = "/", Method = "POST", ResponseFormat = WebMessageFormat.Json)]
Person IncrementAge(Person p);
下面是实现:
public Person IncrementAge(Person p)
{
p.age++;
return p;
}
因此,它采用 Person 复杂类型,将 age 属性加一,然后使用 JSON 序列化将其返回。我可以通过向服务发送 POST 消息来测试这个东西:
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"}
这行得通。如果我想要这样的方法怎么办?
Person IncrementAge(Person p, int amount);
所以它会有多个参数。我应该如何构建 POST 消息才能使其正常工作?这可能吗?
谢谢
【问题讨论】:
标签: .net wcf json rest service