Hel*_*ode 2 c# json web-services visual-studio-2013
我在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;
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用它时,我得到以下错误
{
"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"
}
Run Code Online (Sandbox Code Playgroud)
如果是这样的话我会好的,但MaxJsonLentgh设置为2,147,483,647,json.Length设置为21,460,284.
有什么问题,我该如何解决?
尝试在web.config中配置最大长度,如下所示
<configuration>
<system.web.extensions>
<scripting>
<webServices>
<!-- Update this value to set the max length -->
<jsonSerialization maxJsonLength="2147483647" />
</webServices>
</scripting>
</system.web.extensions>
</configuration>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8023 次 |
| 最近记录: |