Note that this question is an off-shoot of a current problem that I have yet to resolve:
Need help resolving an error when WCF service returns DataTable: OutOfMemoryException
I have an existing WCF service whose endpoint is configured for TransferMode.Buffered
and a client application whose connection asks for the same.
The OperationContracts
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 String
and returns a DataTable
derived from SQL execution.
We are having issues with very large tables using this method. Large meaning in-memory footprint.
I am considering implementing TransferMode.Streamed
(or the like), but I can't seem to get a handle on how to do it for just certain methods.
My WCF service starts up, creates the one-and-only endpoint, and that endpoint is Buffered
. So that makes we want to assume that it's all or nothing. That if I change to Streaming
then I would have to make a wholesale rework of all my OperationContract
methods.
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.
Am I missing something, or can this be made to work?
The method I need to fix: (if you want to know about the connection, refer to the referenced question...it's a lot of code)
The 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;
}
The 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;
}