问题
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