Click here to Skip to main content
12,953,865 members (52,556 online)
Click here to Skip to main content


126 bookmarked
Posted 6 Oct 2003

.NET Remoting – Basic Maneuvers

, , 6 Oct 2003
A tutorial on .NET Remoting
using System;
using System.Runtime.Remoting.Messaging; //For [OneWay] attribute.

namespace nsCRemoteObjInterface

	//(1) Refer to CRemoteObj.UpdateProfile
	//(2) Marked Serializable since this object will be passed back and forth between remote object and client.
	public class CProfile
		public string fname;
		public string lname;
		public string user;
		public string passwd;

		public CProfile()

		public CProfile(string firstname, string lastname, string username, string password)


	//(1) You must either put this class in this interface module or in remote object class (CRemoteObj.cs).
	//Otherwise, you may get some reflection problem when you try to register StatusHandler with event evStatus -
	//The framework will look for StatusHandler when in client code:
	//		CStatusEventSink esStatusEvSink = new CStatusEventSink();
	//		StatusEvent event_delegate = new StatusEvent(esStatusEvSink.StatusHandler);
	//		obj.evStatus += event_delegate; 
	//When obj.evStatus += event_delegate, the framework loads the assembly that contains the handler - in this case, it's the sink class.
	//(2) Since event sink is instantiated in client's code. Event handler runs in client process.
	//(3) For one reason or another (actually, event is fired on remote object/server side, and handler sink is on the client side), event sink class need to derive from MarshalByRefObject.
	//(4) And, methods it implements must be asynchronous - marked by [OneWay] attribute.
	public class CStatusEventSink : MarshalByRefObject
		public CStatusEventSink()


		public void StatusHandler(object sender, StatusEventArgs e)
			Console.Write("StatusHandler fired. ");
			Console.WriteLine("Event message: {0}", e.Message);


	//When CRemoteObj.AuthenticateLoser() fires "event StatusEvent evStatus", an instance of StatusEventArgs will be serialized to an instance of CStatusEventSink in client's process space.
	//Therefore, StatusEventArgs must be marked Serializable.
	public class StatusEventArgs //Event argument class
		public StatusEventArgs()
			message="Event fired!";

		public StatusEventArgs(string m)

		public string Message
			get { return message; }
			set { message = Message; }

		private string message;

	public interface IRemoteObj
		//Object exposes three dummy methods to client:
		bool AuthenticateLoser(string sUserName, string sPasswd); //simple in/out/return.
		string SetupUser(string sname, string spasswd, out string sTime); //output+return values
		CProfile UpdateProfile(CProfile p); //Pass custom object in/out.

		//Get assembly version from here:
		string GetAssembly();


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Authors

Web Developer
Hong Kong Hong Kong
No Biography provided

Norman Fung
Hong Kong Hong Kong
Me too, I'm a developer.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170525.1 | Last Updated 7 Oct 2003
Article Copyright 2003 by raymond.fung, Norman Fung
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid