Presentation is loading. Please wait.

Presentation is loading. Please wait.

.NET Remoting Chandra sekhar Chandra sekhar. What is.NET Remoting? What is.NET Remoting?.NET Remoting versus Distributed COM..NET Remoting versus Distributed.

Similar presentations


Presentation on theme: ".NET Remoting Chandra sekhar Chandra sekhar. What is.NET Remoting? What is.NET Remoting?.NET Remoting versus Distributed COM..NET Remoting versus Distributed."— Presentation transcript:

1 .NET Remoting Chandra sekhar Chandra sekhar

2 What is.NET Remoting? What is.NET Remoting?.NET Remoting versus Distributed COM..NET Remoting versus Distributed COM..NET Remoting versus Web Services..NET Remoting versus Web Services.

3 To use.NET remoting to build an application in which two components communicate directly across an application domain boundary, you need to build the following: A remotable object. A host application domain to listen for requests for that object. A client application domain that makes requests for that object.

4

5 The server process has to register the remotable class so that it can be activated from another application domain. The.NET distinguishes between 2 types of remotable objects: 1)Server-activated objects :Server-activated objects are registered with RemoteConfigurations RegisterWellKnownServiceType and RegisterWellKnownClientType methods 2)Client-activated object. Client-Activated objects are registered with RegisterActivatedServiceType and RegisterActivatedClientType

6 1) RegisterWellKnownServiceType RemotingConfiguration.RegisterWellKnownServiceType( typeof(RemotableClass), // Remotable Class “RemotableObject”,//URI of remotable class WellKnownObjectMode.SingleCall//Activation Mode OrWellKnownObjectMode.Singleton);

7 2) RegisterActivationServiceType RemotingConfiguration.RegisterActivatedSer viceType( typeof(HelloServiceClass), //Remotable Class ");

8 To make RemotableClass available to remote clients, the server process must also create and register a channel. To make RemotableClass available to remote clients, the server process must also create and register a channel. The channel provides a conduit for communication between an object and a remote client. The channel provides a conduit for communication between an object and a remote client. The.NET Framework class library includes two channels for use on the server side : The.NET Framework class library includes two channels for use on the server side : a) System.Runtime.Remoting.Channels.Tcp.TcpServerChannel b) System.Runtime.Remoting.Channels.Http.HttpServerChannel

9 A client application that wants to create a remote instance of RemotableClass has to do some registration of its own. The.NET provides two client channel types:TCPClientChannel and HttpClientChannel A client application that wants to create a remote instance of RemotableClass has to do some registration of its own. The.NET provides two client channel types:TCPClientChannel and HttpClientChannel RemotingConfiguration.RegisterWellKnownClientType registers a class on the client that’s registered with RemotingConfiguration.RegisterWellKnownServiceType on the server. RemotingConfiguration.RegisterWellKnownClientType registers a class on the client that’s registered with RemotingConfiguration.RegisterWellKnownServiceType on the server. The following statements create and register a client-side TCP channel. The following statements create and register a client-side TCP channel. TcpClientChannel channel = new TcpClientChannel (); ChannelServices.RegisterChannel (channel); RemotingConfiguration.RegisterWellKnownClientType ( typeof (RemotableClass),//Remotable Class “tcp://localhost:1234/RemoteObject”//URL of remotable class. );

10 Server side: RemotingConfiguration.configure(“TimeServer.exe.cinfig”);TimeServer.exe.config<configuration> <wellknown mode="SingleCall" type="Clock, ClockServer" <wellknown mode="SingleCall" type="Clock, ClockServer" objectUri="Clock" /> objectUri="Clock" /> </configuration> Declarative Configuration

11 Client side RemotingConfiguration.Configure ("TimeClient.exe.config"); TimeClient.exe.config<configuration> <wellknown type="Clock, ClockServer" <wellknown type="Clock, ClockServer" url="tcp://localhost:1234/Clock" /> url="tcp://localhost:1234/Clock" /> </configuration>

12 In the server activated objects when the client calls new only a proxy is created. The objects themselves aren’t created until a method call is placed through the proxy. In the server activated objects when the client calls new only a proxy is created. The objects themselves aren’t created until a method call is placed through the proxy. The Client activated objects are created on the server the moment the client calls new. The Client activated objects are created on the server the moment the client calls new. Every client that creates a client-activated object receives a brand new object instance that is unique to that client. Every client that creates a client-activated object receives a brand new object instance that is unique to that client. Server-Activated Vs Client-Activated

13 OBJECT LEASING OBJECT LEASING How long does a remote object live once its activated? How long does a remote object live once its activated? Singleton server-activated objects and client-activated objects lifetimes are controlled by leases that can be manipulated programmatically Singleton server-activated objects and client-activated objects lifetimes are controlled by leases that can be manipulated programmatically A lease is an object that implements the ILease interface defined in System.Runtime.Remoting.Lifetime namespace A lease is an object that implements the ILease interface defined in System.Runtime.Remoting.Lifetime namespace ILease lease = (ILease) base.InitializeLifetimeService(); If(lease.CurrentState == LeaseState.Initial) { Lease.InitialLeaseTime = TimeSpan.FromMinutes(20); Lease.RenewOnCallTime = TimeSpan.FromMinutes (10); } Return lease;

14 Lease Property InitialLeaseTime : Length of time following the activation that the object lives if it receives no method calls. InitialLeaseTime : Length of time following the activation that the object lives if it receives no method calls. RenewOnCallTime : Minimum value that CurrentLeaseTime is set to each time the object receives a call. RenewOnCallTime : Minimum value that CurrentLeaseTime is set to each time the object receives a call. CurrentLeaseTime : Amount of time remaining before the object is deactivated if it doesn’t receive a method call. CurrentLeaseTime : Amount of time remaining before the object is deactivated if it doesn’t receive a method call.

15 <configuration> </configuration> SETTING LEASE DECLARATIVELY

16 TO RENEW LEASE RemotableClass rc = new RemotableClass(); ILease lease = (ILease) RemotingServices.GetLifetimeService (rc); TimeSpan remaining = lease.CurrentLeaseTime; If(remaining.ToltalMinutes <1.0) lease.Renew(TimeSpan.FromMinutes(10));

17 Http Channels and Binary Formatters To use IIS we need HTTP Channels to link application domains. To use IIS we need HTTP Channels to link application domains. We can replace the ClientFormatterSinkProvider and SoapServerFormatterSinkProvider with BinaryClientFormatterSinkProvider and BinaryServerFormatterSinkProvider We can replace the ClientFormatterSinkProvider and SoapServerFormatterSinkProvider with BinaryClientFormatterSinkProvider and BinaryServerFormatterSinkProvider The following Web.config registers Clock to be activated by IIS as a singleton server-activated object. The following Web.config registers Clock to be activated by IIS as a singleton server-activated object.

18 <wellknown mode="Singleton" type=“Clock, ClockServer" <wellknown mode="Singleton" type=“Clock, ClockServer" objectUri=“Clock.rem" /> objectUri=“Clock.rem" />


Download ppt ".NET Remoting Chandra sekhar Chandra sekhar. What is.NET Remoting? What is.NET Remoting?.NET Remoting versus Distributed COM..NET Remoting versus Distributed."

Similar presentations


Ads by Google