Returning Azure BLOB from WCF service as a Stream - Do we need to close it?

不想你离开。 提交于 2019-12-02 09:08:57

I'd consider changing your return type to byte[]. It's tidier.

Stream implements IDisposable, so in theory the consumer of your method will need to call your code in a using block:

using (var receivedStream = new FileService().ServeHttpRequest(someUrl))
{
   // do something with the stream
}

If your client definitely needs access to something that Stream provides, then by all means go ahead and return that, but by returning a byte[] you keep control of any unmanaged resources that are hidden under the covers.

OperationBehaviorAttribute.AutoDisposeParameters is set to TRUE by default which calls dispose on all the inputs/outputs that are disposable. So everything just works.
This link :
http://devdump.wordpress.com/2008/12/07/disposing-return-values/
explains how to manually control the process.

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