90 likes | 306 Views
.NET Remoting. A Distributed Application Cookbook. Agenda. Brief overview of Remoting Technicalities for creating a distributed application based on Remoting Examples will be uploaded to the course site. Remoting. RMI – Remote Method Invocation (JAVA) RPC – Remote Procedure Call (.NET).
E N D
.NET Remoting A Distributed Application Cookbook
Agenda • Brief overview of Remoting • Technicalities for creating a distributed application based on Remoting • Examples will be uploaded to the course site
Remoting • RMI – Remote Method Invocation (JAVA) • RPC – Remote Procedure Call (.NET) Costumizable! Client Server Remote invocation f y f(x) Object h On runtime transparent to client Standard development syntax
Step 1 – Miscellaneous • Create three modules • A client module • Holds client code • Will ultimately run the client process (console application) • A server module • Holds server code • Will ultimately run the server process (console application) • A commonlibrary • This module contains all the declarations\definitions that are common to the client and the server (DLL)
Step 2 – Creating the remote object • In the common library module Declare an interface exposing your remote objects methods • In the server module, declare the object’s class extendingMarshalByRefObject and implementing the interface
Step 3 – Hosting the object • The object is hosted in the server process • Programmatically: • Using a configuration file SoapServerFormatterSinkProvider server = newSoapServerFormatterSinkProvider(); server.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; IDictionary prop = newHashtable(); prop["port"] = 9999; ChannelServices.RegisterChannel(newHttpChannel(prop, null, server), false); RemotingConfiguration.RegisterWellKnownServiceType( Type.GetType("Server.Program, Server"), "Service", WellKnownObjectMode.Singleton);
Step 4 – Instantiation at the client • The object is instantiated and accessed in the client process • Programmatically: • Using a configuration file SoapServerFormatterSinkProvider server = newSoapServerFormatterSinkProvider(); server.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; IDictionary prop = newHashtable(); prop["port"] = 0; //listens on an arbitrary port ChannelServices.RegisterChannel(newHttpChannel(prop, null, server), false); Common.IService service = (Common.IService)Activator.GetObject(typeof(Common.IService), "http://localhost:9999/Service");
Custom Sinks • A class implemeting the sink • Extend BaseChannelSinkWithProperties • Implement IClientChannelSink or IserverChannelSink • Implement IMessageSink if placed before the formater sink • A sink provider class • Implementing IClientChannelSinkProvider or IServerChannelSinkProvider • Actually passed to the channel