1 / 23

.Net Remoting

.Net Remoting. Pooja Panjala 06/17/10. Agenda. What is .net Remoting? Explanation of terms Architecture Implementation of Remoting Sample example. What is Remoting in .Net?. It is a mechanism for communicating between objects which are not in the same process.

yale
Download Presentation

.Net Remoting

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. .Net Remoting Pooja Panjala 06/17/10

  2. .net Security Agenda • What is .net Remoting? • Explanation of terms • Architecture • Implementation of Remoting • Sample example

  3. .net Security What is Remoting in .Net? • It is a mechanism for communicating between objects which are not in the same process. • Enables different applications located on same computer or different computer to communicate with objects. • Provides a framework that allows objects to interact with each other across application domains.

  4. .net Security Remoting Components • A remotable object: Which is an object that contain some properties and methods located in one application domain and you need to call its methods or properties from another application domain or process. • A host application: This is the host of the remotable object also called as the server application. The main task of this host is to listen to requests for the hosted remotable object. • A client application: This is the application which makes requests for the remotable object.

  5. .net Security Remote Objects • It is an object outside the application domain of the caller application. • Any object can be changed into a remote object by deriving it from MarshalByRefObject, or by making it serializable either by adding the [Serializable]tag or by implementing the ISerializable interface.

  6. .net Security Types of .NET Remotable Objects • Single Call object: Service one and only one request coming in. • Singleton Call object : Service multiple clients and is useful when data needs to be shared explicitly between several clients. • Client-Activated object : Richer than singleton in many aspects as they can store the state information between method calls for its specific client.

  7. .net Security Proxy object • A proxy object is an object that acts in place of some other object. • Created when client activates a remote object. • It is an instance of the TransparentProxy class, directly available to the client to communicate with the remote object.

  8. .net Security Marshalling • Specifies how a remote object is exposed to the client application. • It is the process of packaging an object access request in one application domain and passing that request to another domain.

  9. .net Security Two methods • Marshalling objects by value • analogous to having a copy of the server object at the client. • Marshal by value classes must either be marked with the [Serilaizable] attribute in order to use the default serialization, or must implement the ISerializable interface. • Marshalling objects by reference • analogous to having a pointer to the object. • Marshal by reference classes must inherit from System.MarshalByRefObject.

  10. .net Security Channels • It is a mechanism by which a stream of bytes is sent from one point to the other. • Two pre-defined .NET Remoting channels existing in System.Runtime.Remoting.Channels are TCPChannel and the HTTPChannel.

  11. .net Security Serialization formatters • .NET Remoting uses serialization to copy marshal-by-value objects, and to send reference of objects which are marshal-by-reference, between application domains. • Formatters are used for encoding and decoding the messages before they are transported by the channel.

  12. .net Security Two types of formatters • binary(System.Runtime.Serialization.Formatters.Binary) • Use binary encoding where performance is critical • Small size • SOAP (System.Runtime.Serialization.Formatters.Soap) • Use XML encoding where interoperability with other remoting frameworks is essential.

  13. .net Security Architecture • Client’s call • proxy to remote object • method invocation on remote object • Message encoded • Call sent to the server using channel

  14. .net Security Implementation of Remoting • Create a Remotable Object MyRemotableObject.cs namespace RemotableObjects { public class MyRemotableObject : MarshalByRefObject { public MyRemotableObject() { } public void SetMessage(string message) { Cache.GetInstance().MessageString = message; } } }

  15. .net Security Create a Server to Expose the Remotable Object namespace RemotableObjects { public class frmRServer : System.Windows.Forms.Form, IObserver { private System.Windows.Forms.TextBox textBox1; private MyRemotableObject remotableObject; private System.ComponentModel.Container components = null; public frmRServer() { InitializeComponent(); remotableObject = new MyRemotableObject(); // using TCP protocol TcpChannel channel = new TcpChannel(8080); ChannelServices.RegisterChannel(channel); RemotingConfiguration.RegisterWellKnownServiceType( typeof(MyRemotableObject),"HelloWorld", WellKnownObjectMode.Singleton); RemotableObjects.Cache.Attach(this); } } }

  16. .net Security • Create a Client to Use the Remotable Object • namespace RemotableObjects • { • public class frmRCleint : System.Windows.Forms.Form • { • private System.Windows.Forms.TextBox textBox1; • MyRemotableObject remoteObject; • private System.ComponentModel.Container components = null; • public frmRCleint() • { • InitializeComponent(); • // using TCP protocol • // running both client and server on same machines • TcpChannel chan = new TcpChannel(); • ChannelServices.RegisterChannel(chan); • // Create an instance of the remote object • remoteObject = (MyRemotableObject) Activator.GetObject( typeof(MyRemotableObject),"tcp://localhost:8080/HelloWorld"); • } • private void textBox1_TextChanged(object sender, System.EventArgs e) • { • remoteObject.SetMessage(textBox1.Text); • } • } • }

  17. .net Security Step 1: Creating the Server Server.cs using System;using System.IO;using System.Runtime.Remoting;using System.Runtime.Remoting.Channels.HTTP;namespace Server { public class ServiceClass : MarshalByRefObject { public void AddMessage (String msg) { Console.WriteLine (msg); } } public class ServerClass { public static void Main () { HTTPChannel c = new HTTPChannel (1095); ChannelServices.RegisterChannel (c); RemotingServices.RegisterWellKnownType ("Server","Server.ServiceClass","ServiceClass", WellKnownObjectMode.Singleton); Console.WriteLine ("Server ON at 1095"); Console.WriteLine ("Press enter to stop the server..."); Console.ReadLine (); } }}

  18. .net Security Compile this file using csc /r:system.runtime.remoting.dll /r:system.dll Server.cs This will generate a executable Server.exe , run this file and on the console u should see Server ON at 1095 Press enter to stop the server...

  19. .net Security Step 2: a) Creating Client Proxy soapsuds -url:http://<Machine Name >:1095/ServiceClass -oa:Server.dll This will create a proxy called Server.dll which will be used to access the remote object

  20. .net Security Step 2: b) Creating Client Code TheClient.cs using System; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels.HTTP;using Server;public class TheClient {public static void Main (string[] args) {HTTPChannel c = new HTTPChannel (1077); ChannelServices.RegisterChannel (c);ServiceClass sc = (ServiceClass) Activator.GetObject (typeof (ServiceClass),http://<Machine where Service is Running >:1095/ServiceClass); sc.AddMessage ("Hello From Client"); }}

  21. .net Security Compile it using csc /r:system.runtime.remoting.dll /r:system.dll /r:Server.dll TheClient.cs The output will be TheClient.exe, run it and check the server console on Machine 1, you will see "Hello From Client".

  22. .net Security References • http://msdn.microsoft.com/en-us/library/2e7z38xb(v=VS.71).aspx • http://www.codeproject.com/KB/IP/Net_Remoting.aspx

  23. .net Security Thank you!

More Related