有人见过吗?在看《C#高级编程》这本书中介绍的,一字不漏的抄进去居然有异常。不知道这个错在哪里?引发异常代码:
Hello obj = (Hello)Activator.GetObject(typeof(Hello),"tcp://localhost:8016/Hi");
Hello obj = (Hello)Activator.GetObject(typeof(Hello),"tcp://localhost:8016/Hi");
解决方案 »
- c#如何使获取的时间同步
- VS 2008打包后的卸载
- 请教一个XML问题
- 调用windows media services sdk
- 如何把类似 \ue2b7\ue9b1\uf09f\uf7bd\ufea7\u05b7\u0ca5 这种unicode编码转成汉字输出?
- c# listview与xls表之间的问题
- 在c#2003中用api使用串口,要如何设置类似vb中RTSEnable的值?
- 请问有关于编程风格的介绍吗?
- WinForm不能拖动!显示不正常!在线等待。。。。。。
- 从Excel导入到oracle时出错,求助~
- [散分]工作半年了,C#學習無進展,鬱悶,散分
- WinForm 中如何获得所有打开窗体的实例?
using System;namespace RemotingTest_Prj.RemoteTest
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class Hello
{
public Hello()
{
Console.WriteLine("Hello 被构造");
}
~Hello()
{
Console.WriteLine("Hello 被析构");
} public string Greeting(string name)
{
Console.WriteLine("Greeting called");
return "Hello," + name;
}
}
}//////////////////////// 客户端代码 //////////////////////////using System;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using RemotingTest_Prj.RemoteTest;namespace Remoting_Client.Client
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class HelloClient
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
ChannelServices.RegisterChannel(new TcpClientChannel()); //注册一个通道
Hello obj = (Hello)Activator.GetObject(typeof(Hello),"tcp://localhost:8016/Hi");
if (obj == null)
{
Console.WriteLine("Could not locate server");
}
for(int i=0;i<5;i++)
{
Console.WriteLine(obj.Greeting("Ray"));
}
}
}
}//////////////////////// 服务器端代码 //////////////////////////
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;namespace RemotingTest_Prj.RemoteTest
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class HelloServer
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
TcpServerChannel channel = new TcpServerChannel(8016);
ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Hello),"Hi",WellKnownObjectMode.SingleCall);
Console.WriteLine("Press return to exit");
Console.ReadLine();
}
}
}
//////////////////////// 公共库端代码 //////////////////////////
using System;namespace RemotingTest_Prj.RemoteTest
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class Hello : MarshalByRefObject //这里加上
{
public Hello()
{
Console.WriteLine("Hello 被构造");
}
~Hello()
{
Console.WriteLine("Hello 被析构");
} public string Greeting(string name)
{
Console.WriteLine("Greeting called");
return "Hello," + name;
}
}
}这个改成这样看看向命运发出战书,誓将命运踩在脚下!!