remoting 本地一切正常 放到服务器就是回调的时候总是出错误
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Serialization.Formatters;
using System.Collections;
using Share;
namespace Server
{
class Server
{
static void Main(string[] args)
{
SoapServerFormatterSinkProvider serverFormatter = new SoapServerFormatterSinkProvider();
serverFormatter.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
Hashtable ht = new Hashtable();
ht["name"] = "ServerChannel";
ht["port"] = 9000;
HttpChannel channel = new HttpChannel(ht, null, serverFormatter);
ChannelServices.RegisterChannel(channel, false);
string identifier = "UpdateObject.rem";
WellKnownObjectMode mode = WellKnownObjectMode.Singleton;
WellKnownServiceTypeEntry entry = new WellKnownServiceTypeEntry(typeof(UpdateObject),identifier, mode);
RemotingConfiguration.RegisterWellKnownServiceType(entry);
RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;
RemotingConfiguration.CustomErrorsEnabled(false);
Console.WriteLine("Server .... , Press Enter key to exit.");
Console.ReadLine();
}
}
}
//-------------------------------------------------服务器
using System;
using System.Collections.Generic;
using System.Text;
namespace Share
{
[Serializable]
public class UpdateObject:MarshalByRefObject
{
public delegate void CheckUpdateEventHandler(string s);
public event CheckUpdateEventHandler CheckUpdate; //消息接收事件
public void OnCheckUpdate(string Message)
{
Console.WriteLine("One Infomation has Updated");
if (CheckUpdate != null)
{
RaiseEvents(ref CheckUpdate,ref Message);
}
}
public UpdateObject()
{
Console.WriteLine("one person needs infomations");
}
public override object InitializeLifetimeService()
{
return null;
}
public void RaiseEvents(ref CheckUpdateEventHandler e, ref string Message)
{
CheckUpdateEventHandler creh = null;
int i = 1;
Delegate[] D = e.GetInvocationList();
foreach (Delegate d in D)
{
try
{
creh = (CheckUpdateEventHandler)d;
creh(Message);
}
catch(Exception tion)
{
Console.WriteLine(tion.ToString());
Message += "\n第 " + i.ToString() + " 个订阅者发生错误,系统取消其事件订阅!";
e -= creh;
}
i++;
}
}
public void BeginInvokeMethod( IAsyncResult result)
{
Console.WriteLine("Begion invoke");
}
}
}
//--------------------------------------------远程对象
using System;
using System.Collections.Generic;
using System.Text;
namespace Receiver
{
[Serializable]
public abstract class ReceiverObject:MarshalByRefObject
{
public abstract void Message_Receive1(string s);
public delegate void NoticeClientEventHandler(string s);
public abstract event NoticeClientEventHandler NoticeClient; //消息接收事件
}
}
//-------------------------------------------用于回调的远程对象
HttpChannel channel = new HttpChannel(9003);
ChannelServices.RegisterChannel(channel, false);
x = (Share.UpdateObject)Activator.GetObject(typeof(UpdateObject), "http://x.x.x.x:9000/UpdateObject.rem");
x.CheckUpdate += new Share.UpdateObject.CheckUpdateEventHandler(ro.Message_Receive1);
//--------------------------------------------------------订阅事件
UpdateObject y;
y = (Share.UpdateObject)Activator.GetObject(typeof(Share.UpdateObject), "http://x.x.x.x:9090/UpdateObject.rem"); //125.45.61.205;
y.OnCheckUpdate("I love you");
//触发事件
在本地很好 防盗服务器就异常 时回调的时候异常 说无法连接client端订阅事件的对象
服务器是2003