这是Server的代码,Server最后编译成TestRemoting.dll:
using System;
using System.Threading;
using System.Runtime.Remoting;namespace TestRemoting
{
public delegate void HelloEventHandler(object sender, EventArgs e);
/// <summary>
/// Hello 的摘要说明。
/// </summary>
public class Hello:MarshalByRefObject
{
public event HelloEventHandler helloEvent;
Thread t1;

public Hello()
{
} public void beginThread()
{
t1 = new Thread(new ThreadStart(HelloWorld));
t1.Start();
} public void endThread()
{
t1.Abort();
} public void HelloWorld()
{
while(true)
{
Thread.Sleep(1000);
helloEvent(this,null);
}
} public string SayHello()
{
return "hello, world";
}
}
}宿主程序的代码是:
using System;namespace TestServiceHost
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
System.Runtime.Remoting.RemotingConfiguration.Configure("TestServiceHost.exe.config"); while(Console.ReadLine() != "q")
{

}
}
}
}宿主中的配置文件是:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application name="SayHello">
<service>
<wellknown mode="Singleton" type="TestRemoting.Hello,TestRemoting" objectUri="mq" />
</service>
<channels>
<channel ref="http" port="1234">
<serverProviders>
<provider ref="wsdl" />
<formatter ref="soap" typeFilterLevel="Full" />
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>Client端的代码是:
using System;
using TestRemoting;using System.Runtime.Remoting;
namespace Client
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1:MarshalByRefObject
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{

System.Runtime.Remoting.RemotingConfiguration.Configure("TestR.exe.config");
Hello hello = new Hello();
hello.helloEvent +=new HelloEventHandler(hello_helloEvent);
} public static void hello_helloEvent(object sender, EventArgs e)
{
Console.WriteLine("I get a message!");
}
}
}client端的配置文件是:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<client>
<wellknown type="TestRemoting.Hello, TestRemoting" url="http://localhost:1234/mq" />
</client>
<channels>
<channel ref="http" port="0" />
</channels>
</application>
</system.runtime.remoting>
</configuration>将宿主程序启动起来,然后再启动Client,出现异常为:未处理的“System.Runtime.Serialization.SerializationException”类型的异常出现在 mscorlib.dll 中。其他信息: 无法找到程序集 Client, Version=1.0.1921.38947, Culture=neutral, PublicKeyToken=null。不知道大家怎样解决