.Net RemotingRemoting IntroductionRemoting BenefitsWhy use .Net Remoting ?.Net Remoting BenefitsSlide 6.Net Remoting BasicsSlide 8Slide 9Slide 10First Remoting ApplicationMarshalByRefObjectsMarshalByRefObjects (CAO)Slide 14Factory Design PatternFactory Design PatternManaging Life Time of an ObjectSlide 18Types of Invocation.Net Remoting vs Web ServicesReferences.Net Remoting.Net RemotingCS-795 Security In Distributed Systems Using .NetSummer 2007Old Dominion UniversityRemoting IntroductionRemoting IntroductionThe process of programs or components interacting across certain boundaries either different processes or machinesDeveloper Speak - Remoting allows you to pass objects or values across servers in different domains using several different protocols.01/15/19 2Remoting BenefitsRemoting BenefitsCentralized Business LogicPhysical Separation of LayersSecure Third Party Access01/15/19 3Why use .Net Remoting ?Why use .Net Remoting ?Objects in different .NET application domains cannot access each other directly◦two apps running on same machine even cannot talk to each other without a third party (text files, logs etc)Enables client code in one application domain to call methods/properties of objects running in another application domain..Net analogy to DCOM01/15/19 4.Net Remoting Benefits.Net Remoting BenefitsMultiple transfer mechanisms – HTTP/TCP◦If there is no web server running – put traffic on port 80Multiple encodings – SOAP/ Binary (your own-serialization).NET Remoting is more flexible (more activation and deployment options).NET Remoting is customizable (you can add logging or other features)01/15/19 5.Net Remoting Benefits.Net Remoting Benefits.Net Remoting enables you to work with stateful objectsInterface description does not have to be manually coded in any way, as metadata can be extracted from running servers, or from any .Net assemblyOne of the major benefits is that it’s centralized around well-known and well-defined standards like HTTP and is directly tied to the .Net Framework01/15/19 6.Net Remoting Basics.Net Remoting BasicsClientProxiesFormatterTransportChannelServerDispatcherFormatterTransportChannelServer-SideObjectFig. The .Net Remoting Architecture01/15/19 7.Net Remoting Basics.Net Remoting BasicsDifferent Ways of defining interfaces:◦Shared Assembly◦Shared Interface or Base Objects◦Generated Metadata Assembly (SoapSuds)Serialization of Data:◦Encoding/Decoding of Objects natively supported◦Just need to mark such objects with [Serializable] attribute or implement the interface ISerializableLifetime Management◦Open network connection between client-server◦Combined reference counting and pinging mechanisms◦Objects get lifetime when created (reset: time-to-live)Sponsor registered with a server-side objectMultiserver/Multiclient◦.Net automatically keeps track of remote object’s origin01/15/19 8.Net Remoting Basics.Net Remoting Basics2 very different kinds of Objects◦Passed by ReferenceThese objects live on serverOnly ObjRef will be passed aroundThe client usually may not have compiled objects in one of its assemblies, instead only a interface or Base class is available to clientProxy Object takes care of all remoting tasks01/15/19 9.Net Remoting Basics.Net Remoting Basics2 very different kinds of Objects◦Passed by ValueThese objects will be passed over remoting boundariesSerialized into a string or binary representation and restored as a copy on other side of comm. channelEach one has its own copy and run independentlyClient has to have the compiled object in one of its assembliesMust support Serialization[Serializable] class-level attribute or ISerializable interface01/15/19 10First Remoting Application First Remoting Application ICustomerManager: Remote InterfaceCustomer: Data ObjectServer: Implements ICustomerManager interfaceClient: Consuming entityLet us see some code …01/15/19 11MarshalByRefObjectsMarshalByRefObjectsCategorized into 2 groups:◦Server-activated objects (SAOs)◦Client-activated objects (CAOs)SAO:◦Comparable to classic stateless Web Services◦No message travels to server on reference request by a client◦Only when methods are called on this remote reference will the server be notified◦Can be either Singleton / SingleCall◦How SAO (Singleton/SingleCall) works ? … code helps 01/15/19 12MarshalByRefObjects (CAO)MarshalByRefObjects (CAO)CAO:◦An instance of specified class created whenA creation request on the client is encountered using new operator or Activator.CreateInstance() methodAn activation message sent to the server◦Are stateful objects◦Will store state information from one method call to the other01/15/19 13MarshalByRefObjects (CAO)MarshalByRefObjects (CAO)◦Cannot use shared interface or assemblies◦Have to ship the complied objects to the clients or use SoapSuds to extract metadata out of a running server or a server-side implementation assembly◦SoapSuds suggested not be used anymore for .Net to .Net distributed applications◦Instead we use a factory design patternIn this a SAO provides methods to return new instances of the CAOHow CAO (factory design pattern) works ? … code helps01/15/19 14Factory Design PatternFactory Design Patternusing System;Namespace FactoryDesignPattern{class MyClass {}class MyFactory{public MyClass GetNewInstance(){return new MyClass();}}01/15/19 15Factory Design Pattern Factory Design Pattern class MyClient{static void Main(string[] args){ //creating using “new”MyClass obj1 = new MyClass();//creating using a factoryMyFactory fac = new MyFactory();MyClass obj2 = fac.GetNewInstance();}}}01/15/19 16Managing Life Time of an ObjectManaging Life Time of an ObjectLease-based object lifetime◦Each server-object is associated with a lease on creation◦Lease has time-to-live counter, decremented in certain intervals◦In addition, a defined amount of time is added on every method call a client places on remote object◦Upon reaching zero time, framework looks for a sponsor registered with the lease.01/15/19 17Managing Life Time of an ObjectManaging Life Time of an ObjectLease-based object lifetime◦A sponsor is an object running on sever itself, client or any machine reachable via a network◦An object subject to garbage
View Full Document