Please note that this question is disabling the current issue that I haven't solved yet:
Need help resolving the error when returning the WCF DataTable service: OutOfMemoryException
I have an existing WCF service whose endpoint is configured for TransferMode.Buffered and a client application whose connection is requesting the same.
OperationContracts are established methods that I could not easily change, except in very minor ways. For example, we have a method that accepts a SQL query String and returns a DataTable obtained from executing SQL.
We are having problems with very large tables using this method. Great sense in the memory.
I am considering implementing TransferMode.Streamed (or the like), but I cannot figure out how to do this for certain methods.
My WCF service starts up, creates a single endpoint and a Buffered endpoint. Therefore, we want to assume that all this or nothing. If I switch to Streaming , then I will have to do a bulk processing of all my OperationContract methods.
There are a few questions that flirt with this subject, but not directly, and not with any answers that really help me where I need to go.
Am I missing something, or can it be made to work?
The method I need to fix: (if you want to know about the connection, refer to the indicated question ... this is a lot of code)
WCF Service 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; }
Client code that uses it:
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; }