title: Can a WCF service support both Buffered and Streamed transfer modes?
body: <p>Note that this question is an off-shoot of a current problem that I have yet to resolve:</p>
  
  <p><a href="https://stackoverflow.com/questions/18149465/need-help-resolving-an-error-when-wcf-service-returns-datatable-outofmemoryexce">Need help resolving an error when WCF service returns DataTable: OutOfMemoryException</a></p>
  
  <p>I have an existing WCF service whose endpoint is configured for <code>TransferMode.Buffered</code> and a client application whose connection asks for the same.</p>
  
  <p>The <code>OperationContracts</code> are established methods that I could not easily modify except in very minor ways.  For example, we have a method that accepts an SQL query <code>String</code> and returns a <code>DataTable</code> derived from SQL execution.</p>
  
  <p>We are having issues with very large tables using this method.  Large meaning in-memory footprint.</p>
  
  <p>I am considering implementing <code>TransferMode.Streamed</code> (or the like), but I can't seem to get a handle on how to do it for just certain methods.</p>
  
  <p>My WCF service starts up, creates the one-and-only endpoint, and that endpoint is <code>Buffered</code>.  So that makes we want to assume that it's all or nothing.  That if I change to <code>Streaming</code> then I would have to make a wholesale rework of all my <code>OperationContract</code> methods.</p>
  
  <p>There are some SO questions that flirt with this subject, but not directly, and not with any answers that really get me where I need to go.</p>
  
  <p>Am I missing something, or can this be made to work?</p>
  
  <p><strong>The method I need to fix:</strong> (if you want to know about the connection, refer to the referenced question...it's a lot of code)</p>
  
  <p>The WCF service code:</p>
  
  <pre><code>[OperationContract]
  DataTable readDataTable(out DbError dbError, String queryString, Boolean SchemaOnly);
  
  public DataTable readDataTable(out DbError dbError, String queryString, Boolean SchemaOnly)
  {
      DataTable dt = new DataTable("ReturnTable");
      dbError = new DbError();
      if (!String.IsNullOrEmpty(queryString))
      {
          try
          {
              command.CommandText = queryString.Replace(new String[] { "{{", "}}", ";;" }, new String[] { "{", "}", ";" });
              SqlDataReader reader = command.ExecuteReader(SchemaOnly ? CommandBehavior.SchemaOnly : CommandBehavior.Default);
              dt.Load(reader);
              reader.Close();
          }
          catch (Exception ex)
          {
              dbError.HasError = true;
              dbError.Error = ex.Message + "\n\n" + queryString;
          }
      }
      return dt;
  }
  </code></pre>
  
  <p>The client code that uses it:</p>
  
  <pre><code>public DataTable readDataTable(String queryString, Boolean SchemaOnly)
  {
      DbError dbError;
      DataTable dt = svcCon.readDataTable(out dbError, queryString, SchemaOnly);
      if (dbError.HasError)
      {
          if (_showErrors)
          ErrorHandler.Show(dbError.Error);
      }
      return dt;
  }
  </code></pre>