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:
byte[]
and return that instead of a Stream
?Stream
different from returning a byte[]
? In the end, .NET Remoting
must somehow serialize the data anyway?Dispose
on 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 calling Dispose()
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 easy to reproduce with a test object I build myself. So this also means I should call Dispose on the client side and it get's proxied back to the object on the server side?
A Stream is a MarshalByRefObject. Thats a special kind. It's a proxy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With