I'm returning Streams from a remote service (.NET Remoting). But Streams are also disposables which as we all know are ment to be disposed.
I could call Dispose on the client side once I finished consuming those. However, I would like to know what exactly happens under the cover when I return a Stream from a remote object.
Especially:
- Should I better read everything into a
byte[]and return that instead of aStream? - Or is .NET remoting doing exactly that for me under the covers anyway?
- If not, how is returning a
Streamdifferent from returning abyte[]? In the end,.NET Remotingmust somehow serialize the data anyway? - Does calling
Disposeon the client side even has any affect at all? Is there any magical connection between the object on the client side and the object on the serverside? I think once it's deserialized behind the covers, there is no sense in callingDispose()on the client side or is there?
I'm answering to Mike Bild here because I also want to improve the question a little
Ok, so the stream talking back to the server is (for me at least) unexpected.
To cosume a remote object one has to do something like this:
public static class ServiceFactory <T>
{
public static T CreateProxy()
{
Type interfaceType = typeof(T);
string uri = ApplicationServer.ServerURL + interfaceType.FullName;
return (T)Activator.GetObject(interfaceType, uri);
}
}
So you are explicitly reaching out for a specific remote object at some URI to consume. And when a method on that remote object returns an object that inherits from MarshallByRefObject that means it automatically is associated with the object on the remote side? Ok, that should be eas