Add filename and length parameter to WCF stream when Transfermode = Stream

2.8k views Asked by At

In contrast to all the SO posts that talk about this topic, I'm not interested in wrapping a stream object in a [MessageContract], since that is not permitted when in streaming mode (afaik).

When I'm in streaming mode, how do I return to the client some metadata, such as length and filename? Can I add a WCF/SOAP header? How would I do this?

I am looking into extending the filestream class and add a [MessageHeader] attribute, but I'm unable to get this to work.

1

There are 1 answers

8
Sergey Mirvoda On BEST ANSWER

here is how we do it

     [MessageContract]
    public class StreamMessage
    {
        [MessageHeader(MustUnderstand = true)]
        public long Length { get; set; }
        [MessageHeader(MustUnderstand = true)]
        public int ServerVersion { get; set; }
        [MessageHeader(MustUnderstand = true)]
        public byte[] Cerificate { get; set; }
        [MessageBodyMember(Order = 1)]
        public Stream Stream;
    }