Lecture 6 -.NET Remting 1. What is.net Remting?.NET Remting is a RPC technique that facilitates cmmunicatin between different applicatin dmains. It allws cmmunicatin within the same prcess, between varius prcesses and between prcesses n different systems. 2. Explain the main elements f.net remting and their purpse. Remte Object : The bject that is running n server. T facilitate remting we need remtable bjects. There are tw methds by which a remte bject can be made available t a lcal client bject: Marshal by value, and Marshal by reference. Channels Channels are used t transprt messages t and frm remte bjects. Bth the client and the server must create a channel. A server channel must specify a well-knwn prt and client use this prt t access service at the server. Perfrming a methd call n the remte bject causes client channel bject t send a message t remte channel bject. Tw mst cmmn.net Remting channels are: i. HTTP Channel : Transprt messages t and frm remte bjects using SOAP prtcl. It is pssible t cnfigure the HTTP Channel t use binary frmatter. ii. TCP Channel : Transprt messages t and frm remte bject in binary frmat. It is als pssible t cnfigure the TCP channel t the SOAP frmatter. Messages Messages are sent thrugh channels. Messages hld infrmatin abut remte bject, called methds and arguments
Frmatter Defines hw messages are transferred int the channel. Frmatters are the bjects used t encde and serialize data int an apprpriate frmat befre they are transmitted ver a channel. Tw frmatter classes are prvided within.net: BinaryFrmatter and SapFrmatter. i. SOAP frmatter : The message is changed int XML and serialized, and required SOAP headers are added. ii. Binary frmatter : All messages are serialized int a binary stream. Prxy bject When a client creates an instance f a remte bject, it receives a prxy t the class instance n the server. The prxy knws abut the public methds f the real bject by using reflectin mechanism t read the metadata frm the assembly. All methds called n the prxy will autmatically be frwarded t the remte class and any results will be returned t the client. Frm the client's perspective, this prcess is n different than making a lcal call. 3. What is meant by server activatin? An activatin mde cntrls bject state management, bject sharing, bject life cycle, and the way in which the client binds t a Marshal by Ref bject. The client decides whether t use client- r server bjects. 4. What are the different activatin methds in.net remting? Client- Client Activated Objects are remte bjects whse lifetime is directly cntrlled by the client. The server creates a separate bject fr each client. Advantage - There is n delay until a methd call is made since bjects are created n new keywrd. Disadvantage - Only partially stateful (i.e. stateful nly fr a given client)
- Activated Objects (SAOs) are remte bjects whse lifetime is cntrlled by the server. The remte bject is instantiated/ when the client calls a methd n the prxy bject. Activated Objects are f tw types Single Call creates an bject fr each remte methd invcatin by clients. Advantage - In client, the bject is created n the new keywrd but if the client des nt call any server methds n that bject, a server bject has been created wastefully. Here, bjects are created when needed and destryed when nt needed. Disadvantage - They are als knwn as stateless because they cannt stre state between requests as there is nly ne request. Singletn One bject services all requests f all clients. Advantage - Als knwn as stateful as they can maintain state acrss requests. Disadvantage - This state hwever is glbally shared between all clients, which generally limit the usefulness f string state infrmatin. Client Singletn Single call 5. Write the fllwing cde. RemtingCnfiguratin.RegisterActivatedServiceType(type f(studentapp)); RemtingCnfiguratin.RegisterWellKnwnServiceType(ty pef(studentapp),"server",wellknwnobjectmde.singlet n); RemtingCnfiguratin.RegisterWellKnwnServiceType(ty pef(studentapp),"server",wellknwnobjectmde.singlec Client string url= "tcp://lcalhst:8001"; RemtingCnfiguratin.RegisterActivatedServiceType(type f(studentapp)); url = "tcp://lcalhst:8001/server"; RemtingCnfiguratin.RegisterWellKnwnClientType(typ ef(studentapp), url); url = "tcp://lcalhst:8001/server"; RemtingCnfiguratin.RegisterWellKnwnClientType(typ ef(studentapp), url);
all); 6. What are the runtime libraries which are needed t perfrm.net Remting? System.Runtime.Remting 7..NET Remting is a cutting edge technlgy fr pint-t-pint interperable applicatin. Cmment n this. Cutting-ege -.Net Remting is nt the latest and mst efficient technlgy. There are new technlgies, sme f which are meant t be replacements f remting. E.g. SOA, WCF Pint-t-pint -.Net Remting can be used t cmmunicate within the same prcess, between varius prcesses and between prcesses n different systems. Interperable -.NET Remting is nt hetergeneus and is prprietary and is therefre, nt interperable. Pint-t-pint cmmunicatin can be perfrmed nly within.net cmpatible languages and platfrms. 8. What is the purpse f using cnfiguratin files t cnfigure the remting details? String cnfiguratin details in the cde has a drawback wuld mean that each time the cnfiguratins are changed applicatin needs recmpiling. Rather than hard-cding the registratin f remte bjects and their channels, we can use a cnfiguratin file. This functinality is available thrugh the System.Runtime.Remting assembly. The details f the cnfiguratin are written in an applicatin cnfiguratin file in XML frmat. 9. In.Net Remting if the server registratin fails the client can smetimes still wrk. Cmment. Even if the registratin with the server fails n the client side, the client can still execute since the server s exe is referenced by the client. In this scenari, the server bject is created n the client side. Methds will execute since there is a lcal server bject but these will nt be remte calls. 10. Explain the differences between marshal by value and extending marshal be reference. Marshal by value These classes are serialized thrugh the channel. Analgus t passing parameters by value.
Classes that shuld be marshaled must be marked with Serializable attribute. Marshal by reference The bjects are nt passed thrugh the channel, but a prxy is returned instead. Analgus t passing parameters by reference. A class marshaled by reference must derive frm MarshalByRefObject.