WCF REST的request方式有两种,一种是xml默认的,一种是json。
JSON:
[WebInvoke(Method = "GET", UriTemplate = "v1/incidents", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
IncidentListResponse GetIncidents();JSON的相对简单,直接调用即可。
XML:
[WebInvoke(Method = "POST", UriTemplate = "v1/tickets", RequestFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml)]
TicketApiResponse UpdateTicketStatus(XmlElement input);XML除了format需要改成XML之外,需要加入bodystyle以及参数是xmlelement。
本文详细介绍了WCF REST服务中两种主要请求格式:JSON与XML。JSON请求较为简单,仅需指定格式即可;而XML请求则更为复杂,除了指定格式外还需要设置body style并使用XmlElement作为参数。
6062

被折叠的 条评论
为什么被折叠?



