我正试图从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
当我拨打我的服务网址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网络配置中。但我得到同样的错误。
答案 0 :(得分:1)
在你的函数中添加这一行。
var javascriptserializer = new JavaScriptSerializer();
javascriptserializer.MaxJsonLength = Int32.MaxValue;
答案 1 :(得分:1)
您的UI项目似乎在ASP.NET MVC框架中,无法从您在问题中指定的web.config设置中读取JavaScriptSerializer
MaxJsonLength
。
要设置MaxJsonLength
,您需要按以下方式在代码中指定值:
var javascriptserializer = new JavaScriptSerializer()
{
MaxJsonLength = Int32.MaxValue // specify length as per your business requirement
};