使用 Jquery 消费 WCF 服务时的 maxJsonLength
我正在开发 Google 地图标记 V3。用户可以添加地图标记和附加信息,这些信息存储在 sql Sever 数据库中。当第一次加载地图页面时,我检索了存储在数据库中的所有标记并将它们显示在地图上。对于 Ajax 调用,我使用 WCF 和 Jquery。一切都工作正常,但有一天我收到一个错误
“使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错。字符串的长度超出了 maxJsonLength 属性上设置的值”。
为此,我增加了 maxJsonLength 的大小,如下所示:
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="5000000"/>
</webServices>
</scripting>
</system.web.extensions>
所以现在我的应用程序再次工作正常。我的问题是,有没有其他方法可以在运行时增加这个 maxJsonLength,因为我必须将此项目交付给我的客户,如果将来发生同样的问题,此功能将停止工作。 我还在 stackoverflow 上找到了一些其他示例 我可以在 web.config 中为 maxJsonLength 设置无限长度吗?
谢谢
I am working on Google Map Marker V3.User can add Map Marker and additional info and this information is stored in sql Sever database. when the map page is loaded first time I retrieved all the markers stored in DB and display them on map. for Ajax call I am using WCF and Jquery. Every thing was working fine but one day I got an error
"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property".
For this I increase the size of maxJsonLength as following:
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="5000000"/>
</webServices>
</scripting>
</system.web.extensions>
So for Now my application again working fine. My question is that is there any other way So that I can Increase this maxJsonLength at run time because I have to deliver this project to my client and if in future this same problem occurred this feature will stop working.
I also found some other example on stackoverflow
Can I set an unlimited length for maxJsonLength in web.config?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将其设置为最大值 2147483644。
在达到最大值之前,您的应用程序可能会出现严重的性能问题,因此在某种程度上它是无限的,因为在达到此限制之前您会遇到其他问题。
将限制设置得非常高会存在问题:
如果我是您,我会坚持您现在拥有的值。并在操作文档中包含信息,即他们看到错误,他们应该增加该值。
You could set it to the max value 2147483644.
Probably your application will have serious performance problems before you hit the max value, so in a way it is unlimited since you will get other problems before you hit this liimtation.
There are problems with setting the limit very high:
If I were you I would stick with the value you have now. And include info in the operations documentation that is they see that error they should increase the value.