我正在我的服务中开发一个应用程序我必须发送一个数组作为参数,
Ext.Ajax.request({
method: 'POST',
contentType: 'application/json; charset=utf-8;',
type: 'json',
url: 'http:/....',
disableCaching: false,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
jsonData: {
FirstName: local_fname_array2,
},
success: function (response) {
console.log(response);
}
});
在服务中....像这样
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/Check1")]
int Psngr(string[] FirstName);
服务定义:
public static int Psngr(string[] FirstName) {
List < Psgr > psgr = new List < Psgr > ();
var getVal = from s in FirstName select s;
int count = getVal.Count();
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["db"].ToString());
con.Open();
using(var cmd = new SqlCommand("SP_InsertCheck1", con)) {
int result;
cmd.CommandType = CommandType.StoredProcedure;
for (int i = 0; i < count; i++) {
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@FirstName", FirstName[i]);
using(var Da = new SqlDataAdapter(cmd))
using(var Ds = new DataSet()) {
Da.Fill(Ds);
result = Convert.ToInt16(Ds.Tables[0].Rows[0]["Result"].ToString());
}
}
return 1;
}
}
但我得到了错误....
服务器在处理请求时遇到错误。异常消息是“格式化程序在尝试反序列化消息时抛出异常:尝试反序列化参数时出错:FirstName。InnerException 消息是“期望状态“元素”。遇到名称为“,命名空间”的“文本”。'。有关更多详细信息,请参阅 InnerException。有关更多详细信息,请参阅服务器日志。异常堆栈跟踪是: