我有一个返回JSON的基于ajax的WebGet方法。它不能处理几千行的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>
下面是结束行为:
<behavior name="Test.AJAXServiceAspNetAjaxBehavior">
<enableWebScript />
<webHttp defaultOutgoingResponseFormat="Json" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
在我看来,一切都是最大的,它应该工作,我可能错过了什么?
我通过改变元数据行为配置上的dataContractSerializer属性来解决这个问题,因为AJAXServiceAspNetAjaxBehavior是不够的。它从服务级别获取了我的maxItemsInObjectGraph属性,而不是endint级别:
<service name="Test.AJAXService" behaviorConfiguration="metadataBehavior">
<endpoint address="" behaviorConfiguration="Test.AJAXServiceAspNetAjaxBehavior"
bindingConfiguration="webHttpConfig"
binding="webHttpBinding"
contract="Test.IAJAXServiceTest" />
</service>
在metadataBehavior: <behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>