Title: .NET Remoting
1.NET Remoting
- A Distributed Application Cookbook
2Agenda
- Brief overview of Remoting
- Technicalities for creating a distributed
application based on Remoting - Examples has been uploaded to the course site
3Remoting
- 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
4Step 1
- 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 common library
- This module contains all the declarations\definit
ions that are common to the client and the server
(DLL)
5Step 2 Creating the remote object
- In the common library module Declare an interface
exposing your remote objects methods - In the server module, declare the objects class
extending MarshalByRefObject and implementing the
interface
6Step 3 Hosting the object
- The object is hosted in the server process
- Programmatically
- Using a configuration file
BinaryServerFormatterSinkProvider
serverSinkProvider new BinaryServerFormatterSink
Provider() serverSinkProvider.TypeFilterLevel
System.Runtime.Serialization.Formatters.TypeFilter
Level.Full IDictionary prop new
Hashtable() prop"port" 9999 // listen on
a specific port ChannelServices.RegisterChannel(n
ew TcpChannel(prop, null, serverSinkProvider),
false) RemotingConfiguration.RegisterWellKnownSe
rviceType( Type.GetType("Serve
r.Program"), "Service",
WellKnownObjectMode.Singleton)
7Step 4 Instantiation at the client
- The object is instantiated and accessed in the
client process - Programmatically
- Using a configuration file
BinaryClientFormatterSinkProvider
clientSinkProvider new BinaryClientFormatterSink
Provider() clientSinkProvider.TypeFilterLevel
System.Runtime.Serialization.Formatters.TypeFilter
Level.Full IDictionary prop new
Hashtable() prop"port" 0 // open an
arbitrary port ChannelServices.RegisterChannel(ne
w TcpChannel(prop, clientSinkProvider, null),
false) Common.IService service
(Common.IService)Activator.GetObject(typeof(Common
.IService),
"tcp//localhost9999/Service")
8Custom Sinks
BinaryFormatter
9Custom Sinks
- A class implementing the sink
- Extend BaseChannelSinkWithProperties
- Implement IClientChannelSink or
IserverChannelSink - Implement IMessageSink if placed before the
formatter sink - A sink provider class
- Implementing IClientChannelSinkProvider or
IServerChannelSinkProvider - Actually passed to the channel
10Custom Sinks Usage
- public IMessage SyncProcessMessage(IMessage
reqMsg) -
- destURI DataServersManager.GetAvailab
leDataServer() - reqMsg.Properties"__Uri"
destURI - // create new next sink with new
URI - nextSink nextSinkProvider.CreateSi
nk(channel, destURI.ToString(), null) - Console.WriteLine("Going to send request to "
(string)reqMsg.Properties"__Uri") - IMethodReturnMessage returnMessage
NextSink.SyncProcessMessage(reqMsg) - return returnMessage
-