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

青春壹個敷衍的年華 提交于 2019-12-13 17:09:03

问题


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:


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;
    }


来源:https://stackoverflow.com/questions/4890636/add-filename-and-length-parameter-to-wcf-stream-when-transfermode-stream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!