Wcf – Passing multiple streams in WCF

wcf

What I have?

I have a WCF contract which accepts a Stream object.

What I need?

I want to convert the contract to accept multiple streams. But, there is some problem with passing multiple streams in WCF. Now I have two options,

(1) Call the WCF method multiple times

(2) Change contract to accept a two dimensional byte array with all file contents

Can somebody tell me which option is better?

Thanks in advance!

Best Answer

We solved this problem by building a Stream wrapper implementation on the client that concatenates a list of streams together, end to end (eg, .Read delegates to the first stream- when it hits EOF on stream 1, it starts reading stream 2, and so on). It has a metadata property that has the names of the streams and their positions, which we include on the call in a [MessageHeader] attributed arg that says what's in the stream and the offsets of each (the client streams must support .Length). The consumer of the streams on the server knows how to read this metadata object and hand out a list of streams in order. The only restriction is that they must be processed in order. Works great!

Related Topic