Developing A Remoting Application: To
Developing A Remoting Application: To
Developing A Remoting Application: To
SingleCall:
-In this mode whenever a request comes from
a client 1 object of remote class gets created
and it's reference is given to client, once the
request is served immediately object gets
destroyed without allowing him to make any
other requests on that object, for a new
request a new object gets created again and
destroyed. Used in the development of single
request app like "Railway PNR Status
Enquiry", "ATM Machines" & "Examination
Results".
4. Server:
-When we want to develop an application to
be consumed from remote machines we
require someone to take the request from
clients. To take a request from client we use
server softwares, which works on the
principles request and response. We can
install multiple server softwares on a
machine, but each server should be running
on a separate logical address known as port.
-In process of developing a Remoting
application it is our responsibility to develop a
server that takes requests of clients to the
Remote Class, because a class is not capable
of taking the request.
-The server which we are going to develop has
to be running on a unique port of the OS. By
default every machine has port's ranging
between 0-65535 in which 0-1023 were OS
reserved ports, rest can be used by any app.
-After developing a Remote Server every
Remote Class on the machine has to be
registered under the Server with an alias
using System.Data.SqlClient;
public class ClsRemoteApp :
MarshalByRefObject, IRemoteApp {
SqlConnection con; SqlCommand cmd; int x
= 0;
public ClsRemoteApp() {
con = new SqlConnection("User
Id=Sa;Password=<pwd>;Database=<db
name>");
cmd = new SqlCommand();
cmd.Connection = con;
}
public string Get_Sname(int sno) {
string name = "";
try {
cmd.CommandText = "Select Sname From
Students Where Sno=" + sno;
con.Open(); name =
cmd.ExecuteScalar().ToString();
}
catch (Exception ex) { ex = null; }
finally { con.Close(); }
return name;
}
public decimal Get_Bal(int custid) {
decimal bal = 0;
try {
cmd.CommandText = "Select Salary From
Customer Where Custid=" + custid;
con.Open();
bal =
Convert.ToDecimal(cmd.ExecuteScalar());
}
catch (Exception ex) { ex = null; }
finally { con.Close(); }
return bal;
}
public string SayHello() {
x += 1;
return "Hello: " + x;
}
public string Demo() {
return "Not accessible to remote clients";
}
}
"XXX",
WellKnownObjectMode.Singleton);
-Now go to design view of the project, right
click on it & select Add Installer which adds 2
components ServiceInstaller1 &
ServiceProcessInstaller1 using which u need
to set the 4 attributes of service. Under
serviceInstaller1 Properties set following:
1. DisplayName: RemoteServer
2. Description: Takes request from remote
clients
3. StartupType: Automatic.
-Under serviceProcessInstaller1 Properties set
Account property as Local System & build
the Project which creates an assembly
RemoteServer.exe.
Installing the service on your machine: To
Install the service on a machine we were
given with a command line utility "installutil",
which has to be used as following:
installutil <service exe name>
Note: To un-install a service which is installed
use as following:
using System.Runtime.Remoting.Channels;
using
System.Runtime.Remoting.Channels.Tcp;
Declarations: IRemoteApp ira;
Under Form Load:
string url =
ConfigurationManager.AppSettings.Get("URL")
;
TcpClientChannel chan = new
TcpClientChannel();
ChannelServices.RegisterChannel(chan,
true);
Object obj =
Activator.GetObject(typeof(IRemoteApp), url);
ira = (IRemoteApp) obj;
Under Call SayHello Button:
button1.Text = ira.SayHello();
Under Call Get_Sname Button:
button2.Text =
ira.Get_Sname(int.Parse(textBox1.Text));
Under Call Get_ESal Button:
button3.Text =
ira.Get_Bal(int.Parse(textBox2.Text)).ToString()
;