如您所见,我正在尝试从 json 中的 wcf 服务中获取结果:
public List<InquiryStatus> SearchInquiryStatus(string userid, string datestart, string dateend)
{
string result = "";
using (WebClient ClientRequest = new WebClient())
{
ClientRequest.Headers["Content-type"] = "application/json";
ClientRequest.Encoding = System.Text.Encoding.UTF8;
result = ClientRequest.DownloadString(ServiceHostName + "/MonitoringInquiryService.svc/SearchInquiryStatus/" +
userid + "/"
+ datestart + "/" + dateend
);
}
var javascriptserializer = new JavaScriptSerializer();
return javascriptserializer.Deserialize<List<InquiryStatus>>(result);
}
但我收到此错误:
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
Parameter name: input
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
Parameter name: input
当我调用我的服务 url
http://reporting.demo.ir/MonitoringInquiryService.svc/SearchInquiryStatus/null/'20171106'/'20171113'
时作为注释在浏览器中我得到了结果。
我用谷歌搜索了我的错误,我发现了这个:
<configuration>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000"/>
</webServices>
</scripting>
</system.web.extensions>
</configuration>
我将此添加到我的 UI Web 配置中。但我遇到了同样的错误。
最佳答案
您的 UI 项目似乎在 ASP.NET MVC 框架中,其中 JavaScriptSerializer
MaxJsonLength
无法从您在问题中指定的 web.config 设置中读取。
要设置 MaxJsonLength
,您需要通过以下方式在代码中指定值:
var javascriptserializer = new JavaScriptSerializer()
{
MaxJsonLength = Int32.MaxValue // specify length as per your business requirement
};
关于c# - 字符串的长度超过了 maxJsonLength 属性上设置的值。c#,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47257227/