Click here to Skip to main content
12,299,086 members (52,562 online)
Click here to Skip to main content

Stats

162.6K views
9.7K downloads
126 bookmarked
Posted

.NET Remoting – Basic Maneuvers

, , 6 Oct 2003
A tutorial on .NET Remoting
using System;
using System.Runtime;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Channels.Tcp;

using System.Runtime.Remoting.Lifetime;

using nsCRemoteObj;

namespace nsCRemoteObjServer
{

	class CRemoteObjServer
	{

		[STAThread]
		static void Main(string[] args)
		{
			//*************************************//
			//OPTION 1: programmatically register channel and type information:

			/*
			//Register channel:
			TcpServerChannel tcpchannel = new TcpServerChannel(8086);
            ChannelServices.RegisterChannel(tcpchannel);

			HttpServerChannel httpchannel = new HttpServerChannel(8085);
			ChannelServices.RegisterChannel(httpchannel);

			//Register TYPE:
			RemotingConfiguration.RegisterWellKnownServiceType(
				typeof(nsCRemoteObj.CRemoteObj),
				"CRemoteObjURI",
				WellKnownObjectMode.SingleCall
				);
			*/


			//*************************************//
			//OPTION 2: Register channel and type information with web.config
			//			Take a look at the file. There're two types of activation:
			//			(a) server activated - mode: SingleCall, Singleton 
			//				Configuration file: ./config file/cremoteobjserv(wellknown).config
			//			(b) client activated
			//				Configuration file: ./config file/cremoteobjserv(client).config
			RemotingConfiguration.Configure("cremoteobjserv.config");
			
			Console.WriteLine("CRemoteServer started and listening on tcp(8086) and http(8085).");
			Console.WriteLine("Start time: {0}", System.DateTime.Now.ToString());
			Console.WriteLine("(1) Run client exe to see remoting in action");
			Console.WriteLine("(2) Hit any key to terminate server process.");
			Console.WriteLine();


			//Take this out from here (wrong place), it will throw an exception:            
			//LifetimeServices.LeaseTime = TimeSpan.FromMinutes(3);
			//LifetimeServices.RenewOnCallTime = TimeSpan.FromMinutes(3);

			Console.ReadLine();
			Console.WriteLine("End time: {0}", System.DateTime.Now.ToString());

		}
	}
}

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.

License

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

Share

About the Authors

raymond.fung
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...

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