我正在使用visual studio 2013中的c#创建一个Web服务。 我连接到一个数据库并使用以下代码返回json。
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetCustomer()
{
var json = "";
var customer = from result in dc.Auto_Kada_SIA_Customers
select result;
JavaScriptSerializer jss = new JavaScriptSerializer();
jss.MaxJsonLength = Int32.MaxValue;
json = jss.Serialize(customer);
int t = json.Length;
return json;
}
但是当我尝试使用它时,我收到以下错误
{
"Message": "Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.",
"StackTrace": " at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)",
"ExceptionType": "System.InvalidOperationException"
}
如果是这样的话,我会好的,但MaxJsonLentgh设置为2,147,483,647,json.Length设置为21,460,284。
问题是什么?我该如何解决?
答案 0 :(得分:7)
尝试在web.config中配置最大长度,如下所示
select * from orders inner join
users on orders.orders_users_id=users.users_id