Introduction:
In this article http://netprogramminghelp.com/aspnet/how-to-useperformutilizeaccess-aspnet-remoting-understanding-remoting-concepts/ we allready discussed about remoting.In this article i am going to explain with one sample server and client.
Main:
This demonstration contains 3 programs,
Step 1: Remote Object Creation,
Step 2: Remote Server,
Step 3: Remote Client,
Remote Object Creation,

Creating remote object using marshalbyrefobject,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MyRemoteObject
{
public class MyRemotingObjectClass : MarshalByRefObject
{
public double addition(double i, double j)
{
Console.WriteLine("Adding {0},{1}", i, j);
return i + j;
}
}
}
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MyRemoteObject { public class MyRemotingObjectClass : MarshalByRefObject { public double addition(double i, double j) { Console.WriteLine("Adding {0},{1}", i, j); return i + j; } } } |
Remote Server,

Registering the remote object using tcpchannel,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting;
using MyRemoteObject;
namespace MyRemotingServer
{
class Program
{
static void Main(string[] args)
{
//Creating new Tcp Server Channel
TcpServerChannel local_tcp = new TcpServerChannel(7777);
//Registering Tcp Server Channel
ChannelServices.RegisterChannel(local_tcp,false);
//register the service type
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(MyRemotingObjectClass), "MyRemotingObjectClassServer",
//Singleton:Each incoimg request/message services by same object instance
WellKnownObjectMode.Singleton
//SingleCall:Each incoming request/message serviced by new object instance
// WellKnownObjectMode.SingleCall
);
Console.WriteLine("Click Enter to Close");
Console.ReadLine();
}
}
}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Runtime.Remoting.Channels.Tcp; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting; using MyRemoteObject; namespace MyRemotingServer { class Program { static void Main(string[] args) { //Creating new Tcp Server Channel TcpServerChannel local_tcp = new TcpServerChannel(7777); //Registering Tcp Server Channel ChannelServices.RegisterChannel(local_tcp,false); //register the service type RemotingConfiguration.RegisterWellKnownServiceType( typeof(MyRemotingObjectClass), "MyRemotingObjectClassServer", //Singleton:Each incoimg request/message services by same object instance WellKnownObjectMode.Singleton //SingleCall:Each incoming request/message serviced by new object instance // WellKnownObjectMode.SingleCall ); Console.WriteLine("Click Enter to Close"); Console.ReadLine(); } } } |
Remote Client,

Activating and getting results from remote object,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using MyRemoteObject;
namespace MyRemotingClient
{
class Program
{
static void Main(string[] args)
{
//Make call to activate remote object,
MyRemotingObjectClass objcls =
(MyRemotingObjectClass)Activator.GetObject(typeof(MyRemotingObjectClass),
"net.tcp://124.123.164.48:7777");
//functionality part,call the remote object method
double a=10,b=30;
double sum1 = objcls.addition(a,b);
Console.WriteLine("Addition Result is:{0}", sum1);
Console.ReadLine();
}
}
}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Remoting; using MyRemoteObject; namespace MyRemotingClient { class Program { static void Main(string[] args) { //Make call to activate remote object, MyRemotingObjectClass objcls = (MyRemotingObjectClass)Activator.GetObject(typeof(MyRemotingObjectClass), "net.tcp://124.123.164.48:7777"); //functionality part,call the remote object method double a=10,b=30; double sum1 = objcls.addition(a,b); Console.WriteLine("Addition Result is:{0}", sum1); Console.ReadLine(); } } } |
conclusion:
Hope this helps,
Happy coding.
Join the forum and make money by posting answers or discussing various topics here !
Dear admin, thnx for sharing this blog post. I found it wonderful. Best regards, Victoria…