Prof Bill Buchanan Dotnet - Remoting/dotnet - Remoting - HTM
Prof Bill Buchanan Dotnet - Remoting/dotnet - Remoting - HTM
Prof Bill Buchanan Dotnet - Remoting/dotnet - Remoting - HTM
NET Remoting
Prof Bill Buchanan Http://www.dcs.napier.ac.uk/~bill/e_presentations/ dotnet_remoting/dotnet_remoting.htm
Author: Prof Bill Buchanan
Identity service
In-the-cloud computing
Users
Application service
Author: Bill Buchanan
Processing service
In-the-cloud Stateful firewall computing
Client
.NET Remoting
Listener
Proxy
Client
Web Services
Proxy
Web services
Author: Bill Buchanan
Client
.NET Remoting
Listener Proxy (using SOAPSUDS or Add Reference)
Client
Client communicates with the local proxy which hides the complexity of the connection Web services
Author: Bill Buchanan
Web Services
Proxy (using wsdl or Add Reference)
Remote Objects
Remote service In general distributed systems are generally more scalable, more robust, and increase availability of services. The most common distributed protocols are: RPC (Remote Procedure Calls), Microsoft Distributed Object Model (DCOM), Common Object Request Broker Architecture (CORBA) and Java Remote Invocation (RMI). Client requests a remote process
Remote object
Remoting firewall Stateful
Remote object
Remote object
.NET Remoting allows access to objects placed around a network. It has: Communications channel. A formatter. This can be Binary encoded or XML encoded (SOAP).
Remote object
Invok P a ss
objec value t/
Remote object
Ge t re
su lt
Invok P a ss
objec value t/
Remote object
Ge t re
su lt
Encapsulate (SOAP)
Formatter (encoder)
Encapsulate (SOAP)
Author: Bill Buchanan
Communicate
Communicate
Client-activated objects
These have a finite lease time, and once their lease has expired they are deleted (using the garbage collector).
Remote object
Server-activated objects
These can either be defined with a "single call" or with a "singleton". A single call accepts one request from a client, and then performs the action, and is then deleted (with the garbage collector). It is defined as stateless, as it does not hold onto parameters from previous calls. Singletons are stateful and can accept multiple calls, where they remember previous calls, and retain their information. They can thus communicate with multiple clients. Also the lifetime of singletons is controlled by lease-based lifetime.
The main namespaces used for remoting: System.Net. This includes classes relating to the networking elements of the distributed system. System.Runtime.Remoting. This includes classes for the remote aspects of the .NET framework, such as mechanisms for remote communication between objects. System.Web.Services. This includes protocols relating to Web services, such as those relating to HTTP and SOAP. This is defined as the ASP.NET Web services framework.
Client object
Objects passed by reference or value for local objects. For remote it is not possible to pass by reference they must be marshalled.
Server object
Proxy
Remoting System
Channel
Remoting System
Author: Bill Buchanan
Serialisation
Marshalling firewall Stateful
Client object
public class ShowCapital : MarshalByRefObject Server application domain { public ShowCapital() { } public string show(string country) { } }
Creates a DLL On the remote machine
ShowCapital()
Proxy
Remoting System
Channel
Remoting System
Author: Bill Buchanan
Serialisation
Marshalling firewall Stateful
Client object
Remoting System
Channel
Remoting System
Author: Bill Buchanan
Serialisation
Marshalling firewall Stateful
Client object
Server innovation
Proxy
Channel=1234
Remoting System
Author: Bill Buchanan
Remoting System
Channel
Server-activation object
Marshalling firewall Stateful
Channels
using System.Runtime.Remoting.Channel.Http using System.Runtime.Remoting.Channel.Tcp Client object TcpChannel channel = new TcpChannel(1234); ChannelServices.RegisterChannel(channel); Proxy
Channel=1234
Remoting System
Channel
Author: Bill Buchanan
Server-activation object
TCP Channel
Activation
Proxy
Remoting System
Channel
Remoting System
Author: Bill Buchanan
Serialisation
Marshalling firewall Stateful
Client object
Server activation is typically used when remote objects do not required to maintain their state between method calls (single call ), or where there are multiple clients who call methods on the same object instance where the object maintains its state between function calls (singleton).
Proxy
Remoting System
In a client-activated object, the client initiates the object and manages it for its lifetime.
Author: Bill Buchanan
Edinburgh
Client object
Login name: Fred OK Send email To Bert
SAO - Singleton
Proxy
OK
Remoting System
Object mode. This defines the server activation, such as SingleCall or Singleton. WellKnownObjectMode.SingleCall
Object URI. This is the indicator that clients use to locate the object. newclass.ShowCapital
Proxy
Remoting System
Author: Bill Buchanan
Object mode. This defines the server activation, such as SingleCall or Singleton. WellKnownObjectMode.SingleCall
Object URI. This is the indicator that clients use to locate the object. newclass.ShowCapital
Proxy
Remote objects are registered using the RegisterWellKnownServiceType, by passing the required parameters Remoting into the method, such as: System
Client object <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.runtime.remoting> Remoteable <application> newClass.ShowCapital object <service> Proxy <wellknown mode="Singleton" (object.dll) type="newclass.ShowCapital, newclass" Assembly: objectUri="ShowCapital1" /> ShowCapital1 </service> <channels> Remoting <channel ref="tcp server" port="1234" /> System </channels> </application> </system.runtime.remoting> </configuration>
otherwise we can use afirewall file Stateful config
Once registered, the remote object will not instantiate itself, as this requires the client to initiate it, or call a method. This is achieved by a client which knows the URI of the remote object and by registering the channel it prefers using GetObject, such as:
Client object
Remoteable newClass.ShowCapital object Proxy (object.dll) ChannelServices.RegisterChannel(channel); Assembly: ShowCapital sh= (ShowCapital) Activator.GetObject( ShowCapital1 typeof(newclass.ShowCapital),"tcp://localhost:1234/ TcpClientChannel channel = new TcpClientChannel(); ShowCapital1");
Remoting System
Author: Bill Buchanan
Client application domain Along with this, the compiler requires type information about the ShowCapital class when this client code is compiled. This can be defined with one of the following: With a reference to the assembly where the ShowCapital class is stored. Using SOAPSUDS tool to extract metadata directly from the endpoint. SOAPSUDS connects to the endpoint, and extracts the metadata, and generates an assembly or source code that is then used in the client compilation. By splitting the remote object into an implementation and interface class and then use the interface as a reference when compiling the client.
Author: Bill Buchanan
Client object
Proxy
Remoting System
using System; Client application domain using System.Data; namespace newclass { public class ShowCapital : MarshalByRefObject { public ShowCapital() Client object { } public string show(string country) { if (country.ToLower()=="england") Proxy return("London"); else if (country.ToLower()=="scotland") return("Edinburgh"); else return("Not known"); } Remoting Channel } System } Serialisation
Remoting System
Author: Bill Buchanan
Channel
Remoting System
Author: Bill Buchanan
Channel
Remoting System
Author: Bill Buchanan
Channel
Remoting System
Author: Bill Buchanan
Client object
Proxy
Remoting System
Author: Bill Buchanan
RemotingConfiguration.Configure( "myconfig.config");
Remoteable object (newclass.dll)
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.runtime.remoting> <application> ShowCapital() <service> <wellknown mode="Singleton" type="newclass.ShowCapital, newclass" objectUri="ShowCapital1" /> </service> <channels> <channel ref="tcp server" port="1234" /> Remoting Channel System </channels> </application> </system.runtime.remoting> </configuration>
Client object <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.runtime.remoting> <application> Proxy
<client>
<wellknown type="newclass.ShowCapital, newclass" url="tcp://localhost:1234/ShowCapital" />
</client>
Remoting System
Author: Bill Buchanan
Serialisation
Remoteable class Stateful firewall
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.runtime.remoting> Channels map onto <application> TCP ports. <service> Standard ports: <wellknown mode="Singleton" type="newclass.ShowCapital, newclass" objectUri="ShowCapital1" /> 21 FTP. <?xml version="1.0" encoding="utf-8" ?> </service> Client <configuration> object <channels> 23 TELNET. <system.runtime.remoting> Remoteable object <channel 56 DNS. </channels> ref="tcp server" port="1234" /> <application> (object.dll) 80 WWW. <client> </application> <wellknown </system.runtime.remoting> 110 POP-3 type="newclass.ShowCapital, newclass" </configuration> ShowCapital() url="tcp://localhost:1234/ ShowCapital" /> Over 1024 for Proxy </client> development </application> </system.runtime.remoting> </configuration>
Remoting System
Channel
Remoting System
Author: Bill Buchanan
Serialisation
Marshalling firewall Stateful
Interface Definitions
using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; for Over 1024 Proxy System.Runtime.Remoting.Channels.Tcp; using development using IDCapital; namespace newclass2 { class Class1 { static void Main(string[] args) { Remoting Channel TcpServerChannel channel = new TcpServerChannel(1234); System ChannelServices.RegisterChannel(channel); RemotingConfiguration.RegisterWellKnownServiceType (typeof(newclass.ShowCapital), "ShowCapital", WellKnownObjectMode.SingleCall); Serialisation Console.WriteLine("Starting..."); Console.ReadLine(); } } }
Remoting System
21 FTP. Client object 23 TELNET. Remoteable object 56 DNS. (object.dll) 80 WWW. private void button1_Click(object sender, System.EventArgs e) 110 POP-3 { ShowCapital() string country,cap; Over 1024 for country=textBox1.Text; Proxy development cap=sh.show(country);
textBox2.Text= cap; } private void Form1_Load(object sender, System.EventArgs e) { TcpClientChannel channel = new TcpClientChannel(); Remoting Channel ChannelServices.RegisterChannel(channel); System sh= (IDCapital.IDCap) Activator.GetObject(typeof(IDCap), "tcp://localhost:1234/ShowCapital"); }
Remoting System
Author: Bill Buchanan
Serialisation
SOAPSUDS
SOAPSUDS
Cram .
Client object requests an instance of the server object. The remoting system creates a proxy of the server object on the client side. The client calls a methods on the server object, and the proxy sends the call through. The remoting system then sends a call to the server remoting system on the server. The remoting system on the server receives the call, and invokes the object on the server. The remote object on the server returns back the result to the remoting system on the server, which sends it to the remoting system on the client. The remoting system on the client sends result to the proxy which forwards it to the client object.
Object marshaling: defines how a remote object is exposed to client applications Marshal-by-value (MBV) objects: These are when objects are copied and passed from the server application domain to the client application domain Which best defines a Marshal-by-reference (MBR) objects: These are when a proxy is used to access a server object, where the client keeps references to the objects Marshal-by-value objects: They reside on the server, and are serialized, and sent over the network to the client. The access is then done locally on the client.
Marshal-by-value object: [Serializable()] public class MyRemoteObject { // ... Marshal-by-reference: public class MyRemoteObject: MarshalByRefObject { // ... }
Small objects, which type is likely to be the fastest: Marshal-by-value Large objects, which type is likely to be the fastest: Marshal-by-reference Objects which are only available on the server: Marshal-by-reference
Which is the most efficient methods of channels and formatting: TCP channel, with a binary formatter Which is the least efficient methods of channels and formatting: HTTP channel, with a SOAP formatter Which is the best methods of channels and formatting for interoperability: HTTP channel, with a SOAP formatter Which is the worst methods of channels and formatting for interoperability: TCP channel, with a binary formatter
Default: TCP is BINARY Default; HTTP is SOAP The lifetime of the SAO is controlled by the server, while the lifetime of a CAO is controlled by the client
Conclusions
Protocol
Extensibility
.NET Remoting
.NET Remote: Highly extensible for all .NET components Web Services: Interrupting SOAP messages
Data types
State
.NET Remoting: Any data type Web Services: Defined by XSD, and thus limited
Ease-of-development
Reliability
Web Services
.NET Remoting v. Web Services Stateful firewall
Intranet
Internet
.NET Remoting
Web Services
HTTP/SOAP Binary(/HTTP)
ASP.NET Web Service Wrapper
Business Logic
Data Storage
Message Client
Service
Message
Stateful firewall WCF
Message
Client
Service
Message
Message Service
Author: Bill Buchanan
Client
Service
Stateful firewall Service-oriented