从 AJAX 服务返回大型 JSON 文件 - WCF

发布于 2024-11-19 21:27:16 字数 2301 浏览 3 评论 0原文

我有一个基于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软糖 2024-11-26 21:27:16

我通过更改metadataBehavior 配置上的dataContractSerializer 属性解决了这个问题,因为AJAXServiceAspNetAjaxBehavior 还不够。它从服务级别而不是 Endint 级别获取我的 maxItemsInObjectGraph 属性:

<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>

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:

<service name="Test.AJAXService" behaviorConfiguration="metadataBehavior">   
     <endpoint address="" behaviorConfiguration="Test.AJAXServiceAspNetAjaxBehavior"             
       bindingConfiguration="webHttpConfig"               
       binding="webHttpBinding" 
       contract="Test.IAJAXServiceTest" />   
</service> 

In metadataBehavior:

    <behavior name="metadataBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    </behavior>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文