I am creating a remoting application on c# with a server application and client application and a centralised database using sql server. Any time i run the application the server application runs fine but the client application runs into an error saying requested services not found.
The client and server application depends on a dll file created from class library. the dll file is what the client application use to connect to the database but anytime i run i get requested services not found.
What I have tried:
in the server application i have this code
public TcpChannel channel;
public Main()
{
InitializeComponent();
channel = new TcpChannel(9090);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(Type.GetType("RemotingClass.RemoteClass,RemotingClass"),
"RemoteClass", WellKnownObjectMode.Singleton);
}
private void Main_Load(object sender, EventArgs e)
{
Loadall();
}
and the server application has this code
private RemoteClass remoteClass;
private string URL;
public Main()
{
InitializeComponent();
URL = "tcp://localhost:9090/RemoteClass";
remoteClass = (RemoteClass)Activator.GetObject(typeof(RemoteClass), URL);
}
private void button1_Click(object sender, EventArgs e)
{
remoteClass.Add_Student(txtName.Text, txtAddress.Text, txtPhone.Text);
Loadall();
}
the dll file created from class library is called remotingclass which contain a class called remoteclass and has the following code
public class RemoteClass : MarshalByRefObject
{
DataAccessLayer DAL = new DataAccessLayer();
public DataTable Get_Students()
{
DAL.Open();
DataTable dt = new DataTable();
dt = DAL.SelectData("Get_Student", null);
DAL.Close();
return dt;
}
public void Add_Student(string Name, string Address, string Phone)
{
DAL.Open();
SqlParameter[] para = new SqlParameter[3];
para[0] = new SqlParameter("@Name", SqlDbType.NVarChar, 50);
para[0].Value = Name;
para[1] = new SqlParameter("@Address", SqlDbType.NVarChar, 50);
para[1].Value = Address;
para[2] = new SqlParameter("@Phone", SqlDbType.NVarChar, 10);
para[2].Value = Phone;
DAL.ExecuteCommand("Add_Student", para);
}
public void Update_Student(int ID, string Name, string Address, string Phone)
{
DAL.Open();
SqlParameter[] para = new SqlParameter[4];
para[1] = new SqlParameter("@Name", SqlDbType.NVarChar, 50);
para[1].Value = Name;
para[2] = new SqlParameter("@Address", SqlDbType.NVarChar, 50);
para[2].Value = Address;
para[3] = new SqlParameter("@Phone", SqlDbType.NVarChar, 10);
para[3].Value = Phone;
para[0] = new SqlParameter("@ID", SqlDbType.Int);
para[0].Value = ID;
DAL.ExecuteCommand("Update_Student", para);
}
public void Delete_Student(int ID)
{
DAL.Open();
SqlParameter[] para = new SqlParameter[1];
para[0] = new SqlParameter("@ID", SqlDbType.Int);
para[0].Value = ID;
DAL.ExecuteCommand("Delete_Student", para);
}
dll file also contains a class for connecting to the database called dataaccesslayer
class DataAccessLayer
{
SqlConnection con = new SqlConnection();
public DataAccessLayer()
{
con.ConnectionString = "Data Source=MaximusDebois;Initial Catalog=Remoting;Integrated Security=True";
}
public void Open()
{
if (con.State != ConnectionState.Open)
{
con.Open();
}
}
public void Close()
{
if (con.State != ConnectionState.Closed)
{
con.Close();
}
}
public DataTable SelectData(string procedureName, SqlParameter[] para)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = procedureName;
cmd.Connection = con;
if (para != null)
{
for (int i = 0; i < para.Length; i++)
{
cmd.Parameters.Add(para);
}
}
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
public void ExecuteCommand(string procedureName, SqlParameter[] para)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = procedureName;
cmd.Connection = con;
if (para != null)
{
cmd.Parameters.AddRange(para);
}
cmd.ExecuteNonQuery();
}
}