title: Returning DataTable objects with WCF service
body: <p>This is a strange problem that I am having with WCF trying to send DataTable in the response. I have the following service contract:</p>
  
  <pre><code>[ServiceContract]
  public interface ISapphireDataService {
      [OperationContract]
      DataTable LoadData(string query, DateTime start, DateTime end);
  
      [OperationContract]
      string LoadDataTest();
  }
  </code></pre>
  
  <p>And the following implementation of the methods (where provider is a class that makes the database call and returns back a DataTable):</p>
  
  <pre><code>public DataTable LoadData(string query, DateTime start, DateTime end) {
      //DataSet temp = new DataSet();
      //temp.Tables.Add(provider.LoadData(query, start, end).Copy());
      //return temp;
  
      return provider.LoadData(query, start, end).Copy();
  }
  
  public string LoadDataTest() {
      return "Hello World!";
  }
  </code></pre>
  
  <p>Now, when I leave it like this, I always get an error when calling the LoadData(...) method:</p>
  
  <blockquote>
    <p>An error occurred while receiving the HTTP response to
    <a href="http://localhost:8731/Design_Time_Addresses/DataProviderServiceLibrary/SapphireDataService/" rel="nofollow noreferrer">http://localhost:8731/Design_Time_Addresses/DataProviderServiceLibrary/SapphireDataService/</a>.
    This could be due to the service endpoint binding not using the HTTP
    protocol.<br>
    This could also be due to an HTTP request context being
    aborted by the server (possibly due to the service shutting down).<br>
    See server logs for more details.</p>
  </blockquote>
  
  <p>This is rather odd because the service is configured to use the wsHttpBinding, which I assume uses HTTP propocol. This <strong>error does not occur if I try calling the LoadDataTest() method!</strong></p>
  
  <p>So what I have done was put this table I have gotten from the database into a DataSet object and it worked! No errors or anything of the sort. <strong>BUT, the table that was returned in the DataSet was EMPTY.</strong> All the fields were Null and no data has been transfered/de-serialized properly, it seems :(</p>
  
  <p>This seems to be a common issue but I am yet to see an answer to this that works. Any ideas?</p>