日期:2014-05-18  浏览次数:21102 次

Remoting的事件处理在互联网上不可用吗?
最近做一个项目,需要用到Remoting的远程事件处理。我写了一个例子,在本机运行没问题,可是当我把服务器端拷到服务器上再运行的时候,就不行了。包括我下载的 张逸 老师的 Remoting事件(服务端广播) 示例放到服务器上也不可用。Remoting的事件处理在互联网不可应用吗?

服务器端代码(Server):
using System;
using System.Collections.Generic;
using System.Text;
using ClassLib;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace Server
{
  class Program
  {
  static void Main(string[] args)
  {
  BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
  BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
  serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

  System.Collections.Hashtable props = new System.Collections.Hashtable();
  props["port"] = 8081;
  TcpChannel channel = new TcpChannel(props, clientProvider, serverProvider);
  ChannelServices.RegisterChannel(channel, false);

  RemotingConfiguration.RegisterWellKnownServiceType(typeof(SayHello), "SayHello", WellKnownObjectMode.Singleton);
  RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;

  Console.ReadKey();
  }
  }
}

客户端代码(Client):
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using ClassLib;

namespace Client
{
  class Program
  {
  static void Main(string[] args)
  {
  TcpChannel channel = new TcpChannel();
  ChannelServices.RegisterChannel(channel, false);

  RemotingConfiguration.RegisterWellKnownClientType(typeof(SayHello), "tcp://219.235.3.120:8081/SayHello");

  BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
  BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
  serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

  System.Collections.Hashtable props = new System.Collections.Hashtable();
  props["port"] = 8082;
  props["name"] = "tcp2";
  TcpChannel channel1 = new TcpChannel(props, clientProvider, serverProvider);
  ChannelServices.RegisterChannel(channel1, false);

  RemotingConfiguration.RegisterWellKnownServiceType(typeof(Common.EventCenter), "EventCenter", WellKnownObjectMode.Singleton);
  RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;

  SayHello Hello = new SayHello();
  Common.EventCenter center = new Common.EventCenter();
  center.AfterSaid += new Common.AfterSaidEventHandler(Hello_AfterSaid);
  Hello.AfterSaid += new Common.AfterSaidEventHandler(center.Method);
  Hello.Say();
  Console.ReadKey();
  }

  static void Hello_AfterSaid(object sender, Common.AfterSaidEventArgs e)
  {
  Console.WriteLine("事件触发");
  }
  }
}
公共类库代码(Common):
using System;
using System.Collections.