tags:

views:

68

answers:

3

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!

A: 

You might consider MTOM binding and have a data contract with multiple byte[] properties.

Darin Dimitrov
+2  A: 

In WCF, you cannot have multiple stream parameters in a single service method. It's just a system restriction.

See the MSDN documentation on WCF streaming:

Restrictions on Streamed Transfers

Using the streamed transfer mode causes the run time to enforce additional restrictions.

Operations that occur across a streamed transport can have a contract with at most one input or output parameter. That parameter corresponds to the entire body of the message and must be a Message, a derived type of Stream, or an IXmlSerializable implementation. Having a return value for an operation is equivalent to having an output parameter.

So for now, all you can do is call your method several times.

Marc

marc_s
A: 

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!

nitzmahone