WCF Web Service Streaming Guidelines

I am trying to extract a large amount of data from a WCF web service. The request is quite small, and the response message will be very large. The web service is currently throwing SystemOutOfMemory exceptions due to the IIS6 limit on the memory that it can allocate (~ 1.4 GB).

I read on some blogs that streaming implementation will solve my problem.

Can anyone share their experiences with this topic? What interests me most is some sample client and service code that can be used together or any recommendations / recommendations. MemoryStream vs FileStream? Should the return type be Stream, Message, Byte []?

My operation is as follows: (as a rule, it returns a large number of elements in the response array, ~ 200 thousand elements)

MediumSizeResponseClass[] GetData(SmallSizeRequestClass request) 
+4
source share
1 answer

If you want to pass only the response, use transferMode=streamedResponse in your binding configuration. This ensures that only the returned response is transmitted.

The return value of the streaming function must be Stream . Then you can read from this stream and do whatever you need with it (store, analyze, whatever).

So, you have a service contract like this:

 [ServiceContract] interface IYourService { [OperationContract] Stream GetData(SmallSizeRequestClass request); } 

On the server, you simply write the stream, and on the client you read from the stream.

Have you consulted the MSDN docs on streaming WCF ?

+4
source

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


All Articles