我创建了一个远程处理应用程序。类库中的代码是
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";
}
}
控制台应用程序中的代码是
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();
}
}
Windows 应用程序中的代码是
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();
}
它显示为异常Requested Service not found
App.Config 文件中的代码是
<configuration>
<appSettings>
<add key="remote" value="tcp://localhost:1234/TestRemoting"/>
</appSettings>
</configuration>