I need to consume data from a WCF service, which pipes it through a stream. The data itself is contents of an archive file, so it needs additional logic, which I am splitting off into a separate class.
Now, normally, I would use a couple of nested using
statements, like so:
// Inside class that does the retrieval
using (var client = new FooWcfServiceClient(endpointName))
{
// Some logic for specifying the request
using (var dataStream = client.SomeMethod(request))
{
// Consuming logic goes here
}
}
But I do not want my retrieval class from above to be dependent on the class that does the actual work on the dataStream
.
But that means, that I need to somehow pass an open stream out of the method above, without closing the connection.
The solution I came up with is to simply make a decorator like this:
class DisposingStreamDecorator : Stream, IDisposable
and then simply pass both the client and the original stream into the decorator, to be disposed later inside Dispose()
. At the same time all the other members, inherited from Stream
are passed onto the stream it wraps.
Is this a bad design decision? Are there any issues I am not seeing?
dataStream
to another method?using
a wcf client: stackoverflow.com/questions/573872/…