【发布时间】:2018-07-05 15:03:26
【问题描述】:
我正在使用 ASP.Net WebForm 和 C# Web 服务,运行代码时出现以下错误;
Error during serialization or deserialization using the JSON JavaScriptSerializer.
The length of the string exceeds the value set on the maxJsonLength property.
我已尝试将以下内容放入网络配置中,但未解决;
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483644"/>
</webServices>
</scripting>
</system.web.extensions>
我的网络服务;
public class OpenRequisitions
{
public string string1 { get; set; }
public string sstring2 { get; set; }
public string string3 { get; set; }
public string string4 { get; set; }
public string string5 { get; set; }
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<OpenRequisitions> GetOpenReqData(string ReqId, string RequisitionTitle, string City, string Country, string DateCreated)
{
string connectionString = ConfigurationManager.ConnectionStrings["CONN"].ConnectionString;
string commandTextGetOpenRequisitions = Properties.Queries.commandTextGetOpenRequisitions;
List<OpenRequisitions> GetOpenRequisitionData = new List<OpenRequisitions>();
using (SqlConnection con = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(commandTextGetOpenRequisitions, con);
command.CommandType = CommandType.Text;
con.Open();
SqlDataReader rdr = command.ExecuteReader();
while (rdr.Read())
{
OpenRequisitions results = new OpenRequisitions();
results.ReqId = rdr["string1"].ToString();
results.RequisitionTitle = rdr["string2"].ToString();
results.City = rdr["string3"].ToString();
results.Country = rdr["string4"].ToString();
results.DateCreated = rdr["string5"].ToString();
GetOpenRequisitionData.Add(results);
}
}
return GetOpenRequisitionData;
}
【问题讨论】:
-
我看到一篇旧文章说将
maxJsonLength设置为超过999999999会使网站/服务崩溃。尝试减小尺寸。你知道实际退回了多少吗?
标签: c# asp.net json web-services webforms