WCF REST的两种方式

来源:互联网 发布:女生的第一支口红 知乎 编辑:程序博客网 时间:2024/05/16 18:36

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。

0 0