The problem is that you're using WellKnownObjectMode.SingleCall
. As the documentation says:
- SingleCall Every incoming message is serviced by a new object instance.
- Singleton Every incoming message is serviced by the same object instance.
See also the documentation for RegisterWellKnownServiceType:
When the call arrives at the server, the .NET Framework extracts the URI from the message, examines the remoting tables to locate the reference for the object that matches the URI, and then instantiates the object if necessary, forwarding the method call to the object. If the object is registered as SingleCall, it is destroyed after the method call is completed. A new instance of the object is created for each method called.
In your case, the statement c.Real = 4
is a call to the Real
property setter. It makes a call to the remote object, which creates a new object, sets the Real
property to 4, and returns. Then when you set the imaginary
property, it creates a new object, etc.
If you want this to work, you'll have to use WellKnownObjectMode.Singleton
. But you might want to ask yourself if you really want such a "chatty" interface. Every time you set a property, it requires a call through the proxy to the server.
And, finally, you might consider abandoning Remoting altogether. It's old technology, and has a number of shortcomings. If this is new development, you should be using Windows Communications Foundation (WCF). The Remoting documentation says:
This topic is specific to a legacy technology that is retained for backward compatibility with existing applications and is not recommended for new development. Distributed applications should now be developed using the Windows Communication Foundation (WCF).