Professional Documents
Culture Documents
Remo Ting
Remo Ting
Remo Ting
Remoting
Remoting
Distributed Technology:
Advantages:
Reusability
Easy maintenance
2.
3.
Application Architecture:
1.
Single Tire
2.
3.
4.
1.
Single Tire:
2.
Two Tire:
1-Tier Architecture is the simplest, single tier on single user, and is the
equivalent of running an application on a personal computer. All the required component
to run the application are located within it. User interface, business logic, and data
storage are all located on the same machine. They are the easiest to design, but the least
scalable. Because they are not part of a network, they are useless for designing web
applications.
2-Tier Architectures supply a basic network between a client and a server. For
example, the basic web model is a 2-Tier Architecture. A web browser makes a request
from a web server, which then processes the request and returns the desired response, in
this case, web pages. This approach improves scalability and divides the user interface
from the data layers. However, it does not divide application layers so they can be utilized
Page 1
Remoting
separately. This makes them difficult to update and not specialized. The entire application
must be updated because layers arent separated.
3.
Three Tire:
model, the browser acts like a client, middleware or an application server contains the
business logic, and database servers handle data functions. This approach separates
business logic from display and data. So the 3 layers commonly known as: Presentation
Layer (PL/UI), Business Logic Layer(BLL) & Data Access Layer(DAL).
4.
N-Tire: N-tier application structure implies the client/server program model. Where there are more
than three distribution levels or tiers involved, the additional tiers in the application are usually
associated with the business logic tier.
Two tire & three tire comes into the distributed technology. We can develop distributed applications with the
following technologies.
DCOM (Microsoft)
Page 2
Remoting
DCOM
Remoting: Remoting provides .NET to .NET communication in homogeneous and heterogeneous platforms.
Channel: Chanel is a communication between client and server.
TCP Channel
2.
HTTP Channel
1.
2.
a.
Homogeneous platforms
b.
c.
Platform dependent
Heterogeneous platforms
b.
c.
Platform independent
Page 3
Remoting
Formatters: Microsoft provides the following formatters to perform serialization and de-serialization.
1.
Binary Formatter
2.
SOAP formatter
1.
Binary Formatter: It will provide network based stream and used by TCP channel.
2.
SOAP Formatter: It will provide XML based stream and used by HTTP channel.
Remoting Activation Modes: The following hierarchy represent the activation modes.
Marshalling: It is the concept of producing stream to be transmitted between one process to another process.
MarshallByRef: Object will be maintained by the server application and client application will be provided with
reference of the objects.
Server Activated: When client makes a method call, the object will be created on the server this is called as
Server Activated.
Singlecall
One object on the server will provide service to only one client
It does not provide any state
Page 4
Remoting
Singleton
Creating Channel: If you want to create a channel, we have to use TCPChannel class.
TCPChannel Class: This class is defined in System.Runtime.Remoting.Channels.Tcp namespace and it
provides a channel implementation that uses the TCP protocol to transmit messages.
TCPChanne(int): Initializes a new instance (constructor) of the TcpChannel class with a server channel that
listens on the specified port.
Ex:
TCPChannel obj = new TCPChannel(2001);
Ex:
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Demo), "MyName",
WellKnownObjectMode.SingleCall);
Parameters:
1. well- known type i.e. here Demo is a class
2. Alias name and its user defined. It is useful to refer the class for client and server communication
3. How you want to maintain object.
Page 5
Remoting
2.
Server Application
Create Console Application (RemoteServer)
3.
Client Application
Create Windows Application (RemoteClient)
(Class Library)
RemoteClass
(System.Runtime.Remoting.dll)
RemoteServer
request
(Console Application)
RemoteClient
(Windows Application)
Both Server (console application) & Client (windows application) applications are using the class (Demo)
defined in business application (class library).
Note: You have to get reference of System.Runtime.Remoting in both client and server applications, in
order to use the following classes in our applications.
ChanelServices Class
RemotingConfiguration Class
I.
1.
Create C#.Net New Class Library project and save as RemoteClass and write the following
statements in class1.cs
Page 6
Remoting
Note: Above class should be inherit from MarshalByRefObject class, which is defined in System namespace.
b.
2.
Build an application and you can find RemoteClass.dll in ~/bin/debug within project location
folder.
Server Application
a.
b.
In order to access remoting classes in our applications, first get the reference for
System.Runtime.Remoting.dll as shown below.
c.
In solution explorer, right click project name, click on Add Reference and select
System.Runtime.Remoting.dll from .NET tab as shown below.
d.
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting;
using RemoteClass;
namespace RemoteServer
{
class Program
{
static void Main(string[] args)
Page 7
Remoting
{
TcpChannel c = new TcpChannel(2001);
ChannelServices.RegisterChannel(c);
//Will Create only one object to the Demo class and maintaining that object.
//This object will share to each and every client, because we are using Singleton
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(Demo), "MyName", WellKnownObjectMode.Singleton);
Console.WriteLine("Server Started");
}
e.
Note:
In the above program:
2001: Port Number, User defined number
Demo: class name, which is defined in class library (above) project
MyName: Alias name, which we have to refer same in client (below) application
Singleton: How you want to maintain object?
3.
Client Application
a.
b.
In order to access remoting classes in our applications, first get the reference for
System.Runtime.Remoting.dll as shown below.
c.
In solution explorer, right click project name, click on Add Reference and select
System.Runtime.Remoting.dll from .NET tab as shown below.
f.
Page 8
g.
Remoting
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting;
using RemoteClass;
private void Button1_Click(object sender, EventArgs e)
{
try
{
Demo obj = (Demo)Activator.GetObject(typeof(Demo), "tcp://localhost:2001/MyName");
MessageBox.Show(obj.Increment().ToString());
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
h.
Execute an application
Note:
In the above program:
Demo: class name, which is defined in class library (above) project
MyName: Alias name, which we have used in server in (above) application
tcp: using tcp channel
localhost: Server application existing in local system
Page 9
Remoting
If we consider, each window is one client. Totally three clients are connected to the server. Whenever client
gives a request to the server, its created only one object and that object is sharing to each and every client.
i.e. server is maintain or preserving the value. For that reason, we are receiving latest value always, when we
click on button/
//Will Create object to the Demo class and maintaining that object.
//Here one object will create for one client, because we are using SingleCall
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(Demo), "MyName", WellKnownObjectMode.SingleCall);
b.
c.
Page 10
Remoting
If we consider, each window is one client. Totally three clients are connected to the server. Whenever client
gives a request to the server, its created one object to one clineti.e. server is maintain or preserving all
objects information. For that reason, we are receiving same value always, when we click on button.
***
***
***
Page 11