Click here to Skip to main content
15,892,298 members

Remoting: requested services not found

MaximusDebois asked:

Open original thread
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
C#
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
C#
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
C#
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
C#
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();
        }
    }
Tags: C#, SQL Server

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900