tags:

views:

62

answers:

3

Coming from a Java background, this is the way I'm thinking:

The server provides an object to the client. This object should be able to execute on the server.

Server:

private string _S = "A";

public interface IFoo { void Bar(); }

private class Foo : IFoo {
    void Bar() { _S = "B";}
}

public IFoo GetFoo() { return new Foo(); }

Client:

IFoo foo = serverChannel.GetFoo();
foo.Bar();

Remoting is legacy (everyone keeps pointing to WCF instead) and WCF does not support this at all basically ( http://stackoverflow.com/questions/2431510 ), so how should I implement this kind of behavior? Using 3rd party components is possible iff required.

I searched on SO but found no similar question. If this has indeed been answered before, just let me know and I'll delete.

+3  A: 

WCF is indeed message based, Remoting still works.... the real question is: why don't you want to work message based?

Tim Mahy
Because it would simplify my app design :)
mafutrct
@mafuctrct: design-wise, there's no huge difference between calling a method on an interface and sending a message. Its the same thing. With WCF, you can get remoting-like behavior, having an interface with a proxy implementation sending messages behind the scenes.
Peter Lillevold
Yes, but I'd like to have many interfaces, interacting with each other in a simple way. As far as I can tell, that's not so easy with WCF, even though it surely can be imitated.
mafutrct
+2  A: 

If you want type sharing in WCF - like what you described and was in remoting, sharing (interface) declarations in common assemblies on the server and client - you can do it by using the NetDataContractSerializer. It helped others as well.

It's use is discouraged - just like remoting -, contract based messaging seems to be all the rage right now.

I should add that with a proper design you will still end up with a contract/message based application even with .Net Remoting. Your shared interfaces will become the operation contracts, while your shared data class definitions will describe the data contracts/messages you pass.

andras
+3  A: 

I recommend not trying to "remote" objects. It's a dangerous idea.

  1. You don't have local control over remote state. You never do.
  2. Trying to reason about what is the "true" state and what isn't gets very complicated very quickly.
  3. Thinking in terms of messages will likely result in a design which is more "correct" from a networking viewpoint - that is, a design which correctly allocates responsibilities and does not make inappropriate assumptions.
  4. A message-based network app will almost certainly be more robust.
  5. A remoting-based app will typically allow for faster initial development, but result in a ton of extra time in the long run dealing with edge conditions, etc.

Really, don't do it. Remote objects are just kind of bad. At a core level, networking is about transmitting data. Having your program work with the same model will make your life much, much easier in the long run.

kyoryu
That's true. As for the technology - meaning ".NET Remoting" - however, people did successfully develop applications with it. To avoid much of the mess, there were some rules: no callbacks, use only singlecall, no state sharing, put only interfaces/message declarations in common assemblies, remote calls should be obvious in client code etc... So, in the end we were left with defining simple data message classes for our remoting app. It looked a lot like a WCF application. :-)
andras
Exactly. Messaging works, and just about any successful networked app beyond trivial examples is going to look a lot like it's doing messaging.
kyoryu
+1 Interesting point of view. I was not aware that Remoting seemed to cause this kind of issues regularly.
mafutrct
@mafutrct: It's not a problem with any specific remoting technology. It's a problem with the whole idea of remoting. `Foo.Bar` has extremely different meanings for a 'remote object' vs. a local structure, different guarantees of how current data is, different errors that can happen, and vastly different performance characteristics. You can't really just paper over those and pretend they don't exist. Once you acknowledge those differences, as andras pointed out, you end up with something that looks a lot like messaging anyway.
kyoryu