REST服务POST方式 多个参数的调用

♠如果涉及到数据量多,而且涉及需要提交多个实体对象的情况下,服务应该怎么写呢?

♣服务:

一、首先把 BodyStyle = WebMessageBodyStyle.Wrapped 设置好

二、例如传递的有两个参数:

public ServiceResult<string> Save(CAL tmpCal, IList<Attach> listAttach)

假设CAL 和Attach是这样的:

//[Serializable] 之前类这里加了序列化的东东,导致调用服务的时候一直提示400错误。

//这里如果想要保留Serializable,那么就老老实实加DataContract和DataMember 吧,哈哈
public class CAL {
   public string A {get;set;}
   public string B {get;set;} 
} 
public class Attach{
   public string C {get;set;}
   public string D {get;set;} 
}

♥那么到了客户端了:

我使用的是json格式请求,所以json个格式必须这样:

{
"tmpCal":
{"A":"aaa","B":"bbb"} ,
 "listAttach":
[{"C":"ccc","D":"ddd"},{"C":"c1111","D":"d11"}]
}

♦纯手敲,可能会有语法错误的地方。

问题纠结了一天,也当做给自己备个注。。。

原文地址:https://www.cnblogs.com/hinsxun/p/2783918.html