Can the WCF service support both buffer and stream modes?

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; } 
+4
source share
1 answer

This is a big question. I understand the problem. The short answer is that you cannot have both streaming and buffering actions in the same operating contract. Of course, you can run 1-many separate endpoints from the same web service, each with a different port, for example, some of which use buffering, and some with streaming.

And you can configure the host to stream its responses, while the client (using the same endpoint) can buffer its upload requests to the host (and vice versa); It's not a problem. But buffering and streaming responses from one host endpoint are not possible.

We faced the same problem when loading buffering for a client from SQL. For a while, we went to download streams to download, primarily to cure client device timeouts, but found that streaming was also memory intensive. We found that streaming as a technique is also more difficult to work with. That's why we left streaming and went back to buffering, but we use the interactive "chunking" approach to download> 100mb. For example, when it is necessary to deliver 1 GB packets, the host will send the file to pieces of 100 MB, which the client software collects as a single file.

Hope this was helpful.

+2
source

Source: https://habr.com/ru/post/1496615/


All Articles