Stream as a return value in WCF - who disposes it?

前端 未结 3 1175
被撕碎了的回忆
被撕碎了的回忆 2020-12-08 02:18

Let\'s say I have the following WCF implementation:

public Stream Download(string path)
{
    FileStream stream = new FileStream(path, FileMode.Open, FileAcc         


        
3条回答
  •  一整个雨季
    2020-12-08 02:43

    If you wrap the Stream in MessageContract (so you could sent more information in headers), beware that the Stream would not be disposed automatically! As the name of attribute OperationBehavior.AutoDisposeParameters suggests, WCF automatically disposes input/output parameters and thus you have to implement IDisposable on your MessageContract class and close the stream there.

提交回复
热议问题