I am returning Streams from a remote service ( .NET Remoting ). But Streams are also disposable, which, as we all know, should be removed.
I could call Dispose on the client side as soon as I finish using them. However, I would like to know what exactly happens under the cover when I return a Stream from a remote object.
Special:
- Should I better read everything in
byte[] and return it instead of Stream ? - Or does .NET remotely do just that for me under the covers?
- If not, how does returning a
Stream differ from returning byte[] ? After all, should .NET Remoting serialize data in some way? - Does calling
Dispose the client side at all? Is there a magic connection between an object on the client side and an object on the server? I think that after it is deserialized behind covers, it makes no sense to call Dispose() on the client side or is there?
I answer Mike Bild because I also want to improve the question a bit
Good, so the thread returning to the server (for me at least) is unexpected.
To use a remote object, you need 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); } }
This way, you explicitly access a specific remote object when using some URI. And when the method on this remote object returns an object that inherits from MarshallByRefObject, what does it mean that it is automatically associated with the object on the remote side? Well, this should be easy to reproduce using a test object that I create myself. So this also means that I have to call Dispose on the client side and it will be proxied back to the server side object?
Christoph
source share