Click here to Skip to main content
14,177,020 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
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();
        }
    }
Posted
Updated 14-Feb-19 23:08pm
v3
Comments
Richard MacCutchan 15-Feb-19 4:43am
   
Please format your code properly, and also indicate where the problem occurs.
MaximusDebois 15-Feb-19 9:45am
   
The problem occurs when i run the client application, there is an error requested service not found
Gerry Schmitz 16-Feb-19 14:45pm
   
Did you "test" your connection string? It's on the "Open" connection you usually run into problems (if the app is going to run at all).
MaximusDebois 23-Feb-19 2:36am
   
I have found the solution the problem was in the server application. Initial it was this:
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 problem was in the url. I was calling the class in the dll which was remoteclass instead of calling the dll itself which is RemotingClass

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190526.1 | Last Updated 15 Feb 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100