This is a discussion on .NET Remoting within the C# Programming forums, part of the Software Development category; What is .Net Remoting? Can any one explain it...?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| What is .Net Remoting? Can any one explain it...?
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
| Sponsored Links |
| |||
| Hi, .NET remoting is replacement of DCOM. Using .NET remoting you can make remote object calls which lie in different Application Domains. As the remote objects run in different process client calling the remote object can not call it directly. So the client uses a proxy which looks like a real object. When client wants to make method call on the remote object it uses proxy for it. These method calls are called as “Messages”. Messages are serialized using “formatter” class and sent to client “channel”. Client Channel communicates with Server Channel. Server Channel uses as formatter to deserialize the message and sends to the remote object.
__________________ Krishnakumar.S Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily |
| |||
| Hi aman, √ SAO (Server Activated Objects) also called as Well-Known call mode. √ CAO (Client Activated Objects) SAO has two modes “Single Call” and “Singleton”. With Single Call object the object is created with every method call thus making the object stateless. With Singleton the object is created only once and the object is shared with all clients. CAO are stateful as compared to SAO. In CAO the creation request is sent from client side. Client holds a proxy to the server object created on server.
__________________ Krishnakumar.S Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily |
| |||
| In Microsoft .Net there are some advanced concepts of enterprises services available, like Web Services and .Net Remoting. ASP.NET Web services and .NET remoting are two separate paradigms for building distributed applications using Internet-friendly protocols and the .NET framework. Web services typically use SOAP for the message format and require that you use IIS for the HTTP message transport. This makes Web services good for communication over the Internet, and for communication between non-Windows systems. Web services are a good choice for message-oriented services that must support a wide range of client platforms and a potentially heavy load. Remoting can be configured to use either SOAP or Microsoft's proprietary binary protocol for communication. The binary protocol yields higher performance, and is great for .NET to .NET communication, but cannot be used to communicate with non-Windows platforms. Remoting does not require an IIS Web server, making it a good choice for peer-to-peer development, but this also means that it cannot leverage the scalability and performance of IIS to support a high number of connections or requests per second. |
| |||
| Hi, Is .Net remoting is similar to webservices..... What kind of relation between .net remoting and webservices..... CAn any one tell me....
__________________ Krishnakumar.S Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily |
| |||
| Hi saravana! check with the following... Remoting is a framework built into Common Language Runtime (CLR) in order to provide developers classes to build distributed applications and wide range of network services. Remoting provides various features such as Object Passing, Proxy Objects, Activation, Stateless and Stateful Object, Lease Based LifeTime and Hosting of Objects in IIS. I’m not going into detail of these features because it will take 3 to 4 tutorials. Here I’m presenting a simple client/server based application in order to provide you easy and fast hands on Remoting. Remoting Object This is the object to be remotely access by network applications. The object to be accessed remotely must be derived by MarshalByRefObject and all the objects passed by value must be serializable. Code: using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace RemotingSamples
{
public class RemoteObject : MarshalByRefObject
{
//////////////////////////////////////////////////////////////////////////////
///constructor
public RemoteObject()
{
Console.writeline("Remote object activated");
}
//////////////////////////////////////////////////////////////////////////////
///return message reply
public String ReplyMessage(String msg)
{
Console.WriteLine("Client : "+msg);//print given message on console
return "Server : Yeah! I'm here";
}
}
} Code: csc /t:library /debug /r:System.Runtime.Remoting.dll remoteobject.cs This is the server application used to register remote object to be access by client application. First, of all choose channel to use and register it, supported channels are HTTP, TCP and SMTP. I have used here TCP. Than register the remote object specifying its type. Code: using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace RemotingSamples
{
public class Server
{
/////////////////////////////////////////////////////////////////////////////
///constructor
public Server()
{
}
/////////////////////////////////////////////////////////////////////////////
///main method
public static int Main(string [] args)
{
//select channel to communicate
TcpChannel chan = new TcpChannel(8085);
ChannelServices.RegisterChannel(chan); //register channel
//register remote object
RemotingConfiguration.RegisterWellKnownServiceType(
Type.GetType("RemotingSamples.RemoteObject,object"),
"RemotingServer",
WellKnownObjectMode.SingleCall);
//inform console
Console.WriteLine("Server Activated");
return 0;
}
}
} Code: csc /debug /r:remoteobject.dll /r:System.Runtime.Remoting.dll server.cs This is the client application and it will call remote object method. First, of all client must select the channel on which the remote object is available, activate the remote object and than call proxy’s object method return by remote object activation. Code: using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using RemotingSamples;
namespace RemotingSamples
{
public class Client
{
/////////////////////////////////////////////////////////////////////////////
///constructor
public Client()
{
}
//////////////////////////////////////////////////////////////////////////////
///main method
public static int Main(string [] args)
{
//select channel to communicate with server
TcpChannel chan = new TcpChannel();
ChannelServices.RegisterChannel(chan);
RemoteObject remObject = (RemoteObject)Activator.GetObject(
typeof(RemotingSamples.RemoteObject),
"tcp://localhost:8085/RemotingServer");
if (remObject==null)
Console.WriteLine("cannot locate server");
else
remObject.ReplyMessage("You there?");
return 0;
}
}
} Code: csc /debug /r:remoteobject.dll /r:System.Runtime.Remoting.dll client.cs
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
| |||
| hi An Introduction To .NET Remoting .Net remoting lets us work with remote objects programatically. In this article David gives us the 101 on .NET remoting and shows us how to create a remote object..NET Remoting provides a powerful and high performance way of working with remote objects. Architecturally, .NET Remote objects are a perfect fit for accessing resources across the network without the overhead posed by SOAP based Web Services. .NET Remoting is easier to use than Java's RMI, but definitely more difficult than creating a Web Service. In this article we will create a remote object that will return an Object read in from a database. I've also included an alternate object that omits the database functionality in order to allow those that don't have a database available to still play with .NET remoting. note:-continues in next post |
| |||
| An Introduction To .NET Remoting - Creating The Shared Library Fire up Visual Studio.NET. Click on File->New->Project. Choose to create a new "C# Library" and name it ResumeServerLibrary then click on OK. This will create the "shared vocabulary" that both our .NET Remote client and Server will use to communicate. The full code is shown below. If you would like to skip the database access portions, replace the ResumeLoader object with: public class ResumeLoader : System.MarshalByRefObject { public ResumeLoader() { System.Console.WriteLine("New Referance Added!"); } public Resume GetResumeByUserID(decimal userID) { return new Resume(1); } } If you're getting errors that the System.Runtime.Remoting.Channels.Tcp namespace does not exist, make sure that you’ve added a reference to the System.Runtime.Remoting.dll by clicking on the Project->Add Reference menu. using System; using System.Runtime; using System.Data.SqlClient; The namespace we're using for this particular object is DotNetRemoteTest. The object shown below is a MarshalByRefObject, which means that instead of passing ResumeLoader over the wire, we're creating a reference and all of the work including the database work happens completely on the server side. namespace DotNetRemoteTest { public class ResumeLoader : System.MarshalByRefObject { private SqlConnection dbConnection; public ResumeLoader() { this.dbConnection = new System.Data.SqlClient.SqlConnection(); this.dbConnection.ConnectionString = "data source=GRIMSAADO2K;initial catalog=underground;integrated security=SSPI;pers" + "ist security info=True;workstation id=GRIMSAADO2K;packet size=4096"; System.Console.WriteLine("New Referance Added!"); } public Resume GetResumeByUserID(decimal userID) { Resume resume = new Resume(); try { dbConnection.Open(); SqlCommand cmd = new SqlCommand( "SELECT ResumeID, UserID, Title, Body FROM Resume as theResume WHERE theResume.UserID="+ userID +"" , dbConnection ); SqlDataReader aReader = cmd.ExecuteReader(); if(aReader.Read()) { resume.ResumeID=aReader.GetDecimal(0); resume.UserID=aReader.GetDecimal(1); resume.Title=aReader.GetString(2); resume.Body=aReader.GetString(3); } aReader.Close(); dbConnection.Close(); } catch(Exception x) { resume.Title="Error:"+x; } return resume; } } The Resume object needs to be serializable in order to be a return type of a remotely referenced .NET Remote object. The reason for this is the object will have to be turned into raw data to be passed over the network and then re-assembled into an object again at the other end. This object is extremely simple, and to add to the simplicity of this tutorial, the constructor even initializes the fields with some default content: [Serializable] public class Resume { private decimal resumeID, userID; private String body, title; public Resume(decimal resumeID) { this.ResumeID=resumeID; this.UserID=1; this.Body="This is the default body of the resume"; this.Title="This is the default Title"; } public decimal ResumeID { get { return resumeID; } set { this.resumeID=value; } } public decimal UserID { get { return userID; } set { this.userID=value; } } public String Body { get { return body; } set { this.body=value; } } public String Title { get { return title; } set { this.title=value; } } }//END OF RESUME OBJECT }//END OF DotNetRemoteTest namespace note:-continues in next post |
| |||
| An Introduction To .NET Remoting - The Server Object There are actually several ways to create the server object. The most straightforward method is described below. In Visual Studio.NET, click on File->New Project. Choose a Command Line Application and name it ResumeSuperServer. First things first. We need to add references to the required DLLs that will make this program work. Go to Project->Add Reference, and add a reference to the DLL that we created in step 1 by clicking the "Browse" button. In order to use the .NET remoting functionality, you must add a reference to the DLL using Project->Add Reference. Under the .NET tab, choose the System.Runtime.Remoting.DLL and click OK. Next you will need to add a reference to System.Runtime.Remoting.dll in the same way we did in step 1. The object is shown below and is fairly simple and straightforward. I'll explain each of the 3 lines of code that really matter to .NET remoting in the following paragraphs. The TcpServerChannel is one of the two types of channels supported by .NET remoting. This will set up the port number we want our object to respond to requests on, and the ChannelServices.RegisterChannel will bind that port number to the TCP/IP stack on the operating system: TcpServerChannel channel = new TcpServerChannel(9932); ChannelServices.RegisterChannel(channel); The other type of channel that can be set up is HTTP, and is done simply by using the HttpServerChannel object in the System.Runtime.Remoting.Channels.Http namespace. The differances between using an HTTP and a TCP channel can be summed up simply -- If you're working with a local network connection then it's best to use TCP because of it's enhanced performance over using HTTP. If you're working over the Internet then HTTP can sometimes be the only choice depending on firewall configurations. Keep in mind that if you do have control over the firewall, almost all firewalls can be configured to allow TCP traffic through on the port you've chosen to use for your object in addition to the DNAT you'll likely need to employ in most situations. If you don't know how to alter these rules, ask your system administrator. RemotingConfiguration.RegisterWellKnownServiceType (typeof(ResumeLoader), "ResumeLoader", WellKnownObjectMode.SingleCall); This line sets a few parameters on your service and binds the object you want to the name you want to use on this remote object. The first parameter is the object you're binding, typeof(ResumeLoader). The second parameter is the string that is the name for the object on the TCP or HTTP channel. For example, remote clients would refer to the above object as "tcp://localhost:9932/ResumeLoader". The third parameter tells the container what should be done with the object when a request for the object comes in. WellKnownObjectMode.Single call makes a new instance of the object for each client while WellKnownObjectMode.Singleton uses one instance of the object for all callers. The complete code for the object is shown below: using System; using System.Runtime; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; using System.Data.SqlClient; using DotNetRemoteTest; namespace ResumeServerServer { public class ResumeSuperServer { public static void Main(String[] args) { TcpServerChannel channel = new TcpServerChannel(9932); ChannelServices.RegisterChannel(channel); RemotingConfiguration.RegisterWellKnownServiceType (typeof(ResumeLoader), "ResumeLoader", WellKnownObjectMode.SingleCall); System.Console.WriteLine("Press Any Key"); System.Console.ReadLine(); } } } Compile this program and note the location of the generated .EXE file. note:-continues in next post Last edited by rrrajesh84in : 10-04-2007 at 07:41 AM. |
| |||
| An Introduction To .NET Remoting - The Remote Client The ResumeClient object is the test user of our newly created ResumeSuperServer remote object. To start this project go to File->New->Project. Choose a Console Application as the application type and enter "ResumeClient" as the project's name. As in step 2, make sure you add a reference to our shared DLL created in step 1 and the System.Runtime.Remoting DLL. The code shown below has two lines of particular interest to .NET remoting. The first line creates a TCP client channel. This channel is not bound to a port. The second line actually gets a reference to our remote ResumeLoader object. The Activator.GetObject method returns a type of Object that we can then cast into our ResumeLoader. The parameters we pass in are extremely similar to what we passed to the RemotingConfiguration object for the server project. The first parameter is the type of the object. The second is the URI of our remote object: ChannelServices.RegisterChannel(new TcpClientChannel()); ResumeLoader loader = (ResumeLoader)Activator.GetObject( typeof(ResumeLoader), "tcp://localhost:9932/ResumeLoader"); The complete code for our ResumeClient is shown below: using System; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; using DotNetRemoteTest; namespace ResumeClient { public class ResumeClient { public static void Main(string[] args) { ChannelServices.RegisterChannel(new TcpClientChannel()); ResumeLoader loader = (ResumeLoader)Activator.GetObject( typeof(ResumeServer), "tcp://localhost:9932/ResumeLoader"); if(loader==null) { Console.WriteLine("Unable to get remote referance"); } else { Resume resume = loader.GetResumeByUserID(1); Console.WriteLine("ResumeID:"+ resume.ResumeID); Console.WriteLine("UserID:"+ resume.UserID); Console.WriteLine("Title:"+ resume.Title); Console.WriteLine("Body:"+ resume.Body); } Console.ReadLine();//Keep the window from closing before we can read the result. }//END OF MAIN METHOD }//END OF ResumeClient Object }//END OF ResumeClientNamespace Compile this project and note the location of the executable. Testing It Out Create a table in your database with the following basic schema: Table Name-Resume ResumeID, numeric (autonumber) UserID, numeric Title, Char(30) Body, Text Double click on the server executable that we created in step 2 and then double click on the client executable that we created in step 3. If everything works out then you should see the row from the database that has a ResumeID of 1. note:-continues in next post |
| |||
| An Introduction To .NET Remoting - Conclusion In closing, .NET remoting is very simple to use and can provide an excellent way to work with resources across your network or the Internet. In this article we've only touched on the basics of .NET remoting, but hopefully you've now seen enough code to see how useful and efficient .NET remoting can be. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| security measures for .NET Remoting | Arun | ASP and ASP.NET Programming | 1 | 08-18-2007 12:15 AM |
| What are the consideration in deciding to use .NET Remoting or ASP.NET Web Services | Arun | ASP and ASP.NET Programming | 1 | 08-09-2007 07:56 AM |
| What is .NET Remoting ? | oxygen | ASP and ASP.NET Programming | 4 | 08-08-2007 02:37 AM |
| How can we configure a .NET Remoting object via XML file? | mobilegeek | C# Programming | 1 | 07-24-2007 06:46 AM |
| Flash Remoting | nssukumar | Flash Actionscript Programming | 3 | 03-20-2007 05:28 AM |