remoting 本地一切正常 放到服务器就是回调的时候总是出错误

tujunyan 2007-05-23 04:31:28
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
...全文
308 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
wzd24 2007-05-24
  • 打赏
  • 举报
回复
如果是这种模型的话,基本上是无法解决的,我个人的建议是用Socket代替Remoting。
要不就采用Client端采用定时访问Server端的方案。
tujunyan 2007-05-24
  • 打赏
  • 举报
回复
请问怎么办解决?
wzd24 2007-05-24
  • 打赏
  • 举报
回复
应该是Server端无法连接Client端而导致的问题,因为Remoting是TCP短连接,在通讯完成后就会断开Socket连接。当需要再次通讯的时候再次连接。因为你的Client端不是在公网,Server端无法主动连接Client,因此问题就会发生。
tete 2007-05-24
  • 打赏
  • 举报
回复
不会,这能学习,帮顶
tujunyan 2007-05-24
  • 打赏
  • 举报
回复
设置了的 也罢没有用
tujunyan 2007-05-24
  • 打赏
  • 举报
回复
谢谢
tujunyan 2007-05-23
  • 打赏
  • 举报
回复
请问 怎么设置?
CathySun118 2007-05-23
  • 打赏
  • 举报
回复
估计是超时时间设置的问题
tujunyan 2007-05-23
  • 打赏
  • 举报
回复
谢谢帮助 谢谢
tujunyan 2007-05-23
  • 打赏
  • 举报
回复
不会呀 速度很快 连接服务器的时候 用远程
jinta2001 2007-05-23
  • 打赏
  • 举报
回复
我也想知道。
UP
cellblue 2007-05-23
  • 打赏
  • 举报
回复
会是因为超时吗?
tujunyan 2007-05-23
  • 打赏
  • 举报
回复
client 不是直接连接的公网 !!!

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧