Let's say I have the following WCF implementation:
public Stream Download(string path)
{
FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read);
return stream;
}
Who's responsible for disposing the returned value? After all, a network failure might occur, hence the consumer might not be able to dispose it.
Service is responsible for closing stream and unless you change default behavior it does it automatically (the behavior with defalut values is always used). If you set OperationBehavior.AutoDisposeParameters
to false
you must register handler for OperationContext.OperationCompleted
and dispose the stream in the handler as described here.
Client cannot close the stream because client has a different one - you are not passing reference to your stream or reference to your file handler. Internally file content is copied to transport and client processes it in its own stream instance (where he is responsible for disposing it).