Sean Thoman
Sean Thoman

Reputation: 7489

Return large JSON file from AJAX Service - WCF

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?

Upvotes: 3

Views: 1331

Answers (1)

Sean Thoman
Sean Thoman

Reputation: 7489

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>

Upvotes: 5

Related Questions