Question

I have created a Remoting application. The code in class Librery is

 public class InitialClass1:MarshalByRefObject
{
    int i=0;
    public InitialClass1()
    {

    }
    public string getInitial(string nam)
    {                
        i++;
        if (nam.ToLower() == "naresh") return i.ToString()+").Jadapalli";
        else if (nam.ToLower() == "balu") return i.ToString() + "Gonugunta";
        else if (nam.ToLower() == "murali") return i.ToString() + "Vempuluri";
        else if (nam.ToLower() == "chandra sekhar") return i.ToString() + "Ponnam";
        else if (nam.ToLower() == "aneev") return i.ToString() + "Katti";
        else if (nam.ToLower() == "rajini") return i.ToString() + "Karlapudi";
        else
            return i.ToString() + "No results";

    }
}

the code in Console application is

class Program
{
    [STAThread]
    static void Main(string[] args)
    {
        TcpChannel tcp = new TcpChannel(1234);
        ChannelServices.RegisterChannel(tcp,false);
        string s = ConfigurationManager.AppSettings["remote"];
        RemotingConfiguration.RegisterWellKnownServiceType(typeof(InitialClass1),s,WellKnownObjectMode.SingleCall);
        Console.WriteLine("Remoting starting...");
        Console.ReadLine();            
    }
}

Code in Windows application is

 private void button1_Click(object sender, EventArgs e)
    {
        label3.Text = Icls.getInitial(textBox1.Text);
    }

    private void Form1_Load(object sender, EventArgs e)
    {

         string url = ConfigurationManager.AppSettings["remote"];
        TcpChannel chan = new TcpChannel();
        ChannelServices.RegisterChannel(chan, false);

        RemotingConfiguration.ApplicationName = "TestRemoting";
        RemotingConfiguration.RegisterActivatedClientType(typeof(InitialClass1), url);

        Icls = new InitialClass1();

    }

It is showing an exception as Requested Service not found

code in App.Config file is

<configuration>
  <appSettings>
    <add key="remote" value="tcp://localhost:1234/TestRemoting"/>
  </appSettings>
</configuration>
Was it helpful?

Solution 2

My mistake is in server object is console application

TcpChannel tcp = new TcpChannel(1234);
    ChannelServices.RegisterChannel(tcp,false);
    string s = ConfigurationManager.AppSettings["remote"];
    RemotingConfiguration.RegisterWellKnownServiceType(typeof(InitialClass1),s,WellKnownObjectMode.SingleCall);
    Console.WriteLine("Remoting starting...");
    Console.ReadLine(); 

See in registering I am passing s value( ie whole url from app.config file tcp://localhost:1234/TestRemoting). That is the problem. Actually we have to give a desired name in server object as your wish, but the same name only should be in app.config file.

Here my url is tcp://localhost:1234/TestRemoting . In this case we need to give TestRemoting in server object as

RemotingConfiguration.RegisterWellKnownServiceType(typeof(InitialClass1),"TestRemoting",WellKnownObjectMode.SingleCall);

That is only my problem. Now my application is working well..

OTHER TIPS

You should try the initialization in button1_click method i think. Because you want it to initialized whenever button gets clicked.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top