【发布时间】:2014-04-22 08:01:51
【问题描述】:
我使用的是 ASPX 4.5。
客户端发送一个带有动态字段的 JSON 对象(每次可以不同)
function storeDataInSession(formData) {
var data = {};
data["formData"] = formData;
$.ajax({
url: "MY_URL/StoreFormData",
type: "post",
data: JSON.stringify(data),
contentType: 'application/json',
dataType: 'json',
success: function (data, textStatus, xhr) {
console.log(data);
console.log("success");
},
error: function (xhr, textStatus, errorThrown) {
console.log("failure");
}
});
}
在服务器端,我正在尝试将该 JSON 转换为字典,但出现错误 500。
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
public String StoreFormData(dynamic formData)
{
JavaScriptSerializer jss = new JavaScriptSerializer();
Dictionary<string, string> formValues = jss.Deserialize<Dictionary<string, string>>(formData);
return "aaaaa";
}
我做错了什么?
【问题讨论】:
-
为您的服务添加错误处理,这将有助于找出发生了什么错误:stackoverflow.com/questions/23212705/…
-
错误:错误:无法从MYURL获取元数据
-
我注意到您使用的是动态的。 WCF 不允许这样做
标签: c# asp.net json wcf dictionary