Monday, 24 December 2012 13:54

.net remoting in c# application

Written by 
Rate this item
(0 votes)

to create and use the object instances on remote machines .Net remoting
is used,without any DCOM involved.

this article will cover .net remoting with common hosting method in IIS.

1.create a class in c# programming language which inherits
MarshalByRefObject-
public class testObj: MarshalByRefObject
{// ...}
add more classes and properties as needed.

2.compile the class to produce testObj.dll

3.the object to be hosted someplace.the easy way for doing this is to
host this object in IIS.but first of all describe the object in a
web.config file so that it can be accessed as shown below-
<configuration>
<system.runtime.remoting>
<application>
<service>
<wellknown mode="SingleCall" type="testNamespace.testObj, testObj"
objectUri="testObj.soap" />
..

4.after writing in the above config file make a directory "remoteObj".
make a Bin directory beneath the above directory.
5.make a new IIS virtual dir: myTestIISObj.which points to
remoteObj directory.
6.now put the testObj.dll file in Bin directory
7.now put the Web.config file in the remoteObj directory.

client side::

in your application a reference to local object must be set on local
machine.which allows CLR to get meta data of your object so that
you may generate this object remotely.

now set up a client.config file same as web.config file.this file
tells CLR how and where to get the remote object.as shown below-

<configuration>
<system.runtime.remoting>
<application name="Client">
<client url="http://mridul/myTestIISObj">
<wellknown type="testNamespace.testObj, myObj"
url="http://mridul/myTestIISObj/testObj.soap"/>
</client><channels><channel ref="http" />
...

you may replace mridul with the name of ur remote server.
then in the client code,make the object as usual.but at first,load
config file-
//Load your Http Channel from config
try{RemotingConfiguration.Configure("client.config");}
catch{}
//initiate remote object on server(which is just a proxy object)
testNamespace.testObj firstObj = new testNamespace.testObj();

.Net runtime knows the fact that it is a non local object because
config file was read in previouse line.then .Net runtime makes the
object on remote machine.you can now get the object locally &
.Net does the remaining tasks.so in this way you can create a remote
object.

Read 3532 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.