从 AJAX 服务返回大型 JSON 文件 - WCF
我有一个基于 AJAX 的 WebGet 方法,该方法返回 JSON。它不适用于几千行的 JSON 结果(如果我只取 100 行左右,它就可以工作)。我注意到浏览器只是停止运行,没有任何反应,没有任何信息显示 Firebug 控制台:
[WebGet]
public HttpTransactionTransformArgs Test()
{
HttpTransactionFilterArgs args = new HttpTransactionFilterArgs();
args.Context = "MyDb";
args.Entity = "MyDbRow";
args.Key = "1";
args.Option = null;
HttpTransactionTransformArgs targs = new HttpDataPush().TransformRequest(args);
return targs;
}
[DataContract]
[KnownType(typeof(HttpTransactionTransformArgs))]
[KnownType(typeof(HttpColumnDefinition))]
[KnownType(typeof(HttpDataRow))]
public class HttpTransactionTransformArgs
{
[DataMember]
public string EntityName { get; set; }
[DataMember]
public List<HttpColumnDefinition> Schema { get; set; }
[DataMember]
public List<HttpDataRow> Data { get; set; }
[DataMember]
public bool TransactionSuccessful { get; set; }
}
这是我的 WCF 服务器端配置:
<service name="Test.AJAXService" behaviorConfiguration="metadataBehavior">
<endpoint address="" behaviorConfiguration="Test.AJAXServiceAspNetAjaxBehavior"
bindingConfiguration="webHttpConfig"
binding="webHttpBinding" contract="Test.IAJAXServiceTest" />
</service>
这是我正在应用的 webHttpBinding 配置:
<webHttpBinding>
<binding name="webHttpConfig" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"
closeTimeout="00:30:00" openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00" >
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxDepth="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</webHttpBinding>
这是 endpoing 行为:
<behavior name="Test.AJAXServiceAspNetAjaxBehavior">
<enableWebScript />
<webHttp defaultOutgoingResponseFormat="Json" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
在我看来就像一切都已达到极限并且应该可以工作一样,我可能会错过什么?
I have an AJAX-based WebGet method that returns JSON. It won't work with JSON results of a few thousand rows (if I take only 100 or so rows it works). I notice that the browser just stalls and nothing happens, without any information showing the Firebug console:
[WebGet]
public HttpTransactionTransformArgs Test()
{
HttpTransactionFilterArgs args = new HttpTransactionFilterArgs();
args.Context = "MyDb";
args.Entity = "MyDbRow";
args.Key = "1";
args.Option = null;
HttpTransactionTransformArgs targs = new HttpDataPush().TransformRequest(args);
return targs;
}
[DataContract]
[KnownType(typeof(HttpTransactionTransformArgs))]
[KnownType(typeof(HttpColumnDefinition))]
[KnownType(typeof(HttpDataRow))]
public class HttpTransactionTransformArgs
{
[DataMember]
public string EntityName { get; set; }
[DataMember]
public List<HttpColumnDefinition> Schema { get; set; }
[DataMember]
public List<HttpDataRow> Data { get; set; }
[DataMember]
public bool TransactionSuccessful { get; set; }
}
And here is my server-side configuration for WCF:
<service name="Test.AJAXService" behaviorConfiguration="metadataBehavior">
<endpoint address="" behaviorConfiguration="Test.AJAXServiceAspNetAjaxBehavior"
bindingConfiguration="webHttpConfig"
binding="webHttpBinding" contract="Test.IAJAXServiceTest" />
</service>
This is the webHttpBinding config I am applying:
<webHttpBinding>
<binding name="webHttpConfig" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"
closeTimeout="00:30:00" openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00" >
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxDepth="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</webHttpBinding>
And here is the endpoing behavior:
<behavior name="Test.AJAXServiceAspNetAjaxBehavior">
<enableWebScript />
<webHttp defaultOutgoingResponseFormat="Json" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
It looks to me like everything is maxed out and it should work, what might I be missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过更改metadataBehavior 配置上的dataContractSerializer 属性解决了这个问题,因为AJAXServiceAspNetAjaxBehavior 还不够。它从服务级别而不是 Endint 级别获取我的 maxItemsInObjectGraph 属性:
在metadataBehavior中:
I solved this by changing the dataContractSerializer attribute on the metadataBehavior configuration, because the AJAXServiceAspNetAjaxBehavior wasnt enough. It was taking my maxItemsInObjectGraph attribute from the service-level, not the endoint level:
In metadataBehavior: