关于Remoting的问题

cbw99 2003-03-28 03:24:47
我在客户端远程调用服务器对象的时候出现如下错误:
“未处理的“System.Runtime.Remoting.RemotingException”类型的异常出现在 mscorlib.dll 中

其他信息:信道 tcp 已注册。”

这是怎么回事啊?

另外在服务器端运行“TcpServerChannel foChannel = new TcpServerChannel(8086);”的时候有时会报出以下错误:“未处理的“System.Net.Sockets.SocketException”类型的异常出现在 system.runtime.remoting.dll 中

其他信息:参考的对象种类不支持尝试的操作。”

救命啊!!!
...全文
30 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cbw99 2003-03-31
  • 打赏
  • 举报
回复
citymeteor(流星) :
谢谢!!!

Server.CS:
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
TcpServerChannel foChannel = new TcpServerChannel(8086);
ShowChanelProperties(foChannel);
ChannelServices.RegisterChannel(foChannel);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteDLL.RemoteObject ),"RemoteObject",WellKnownObjectMode.SingleCall);
Console.WriteLine("按任意键退出");
Console.ReadLine();
ChannelServices.UnregisterChannel(foChannel);

}

share.cs:

public class CDocument : System.MarshalByRefObject
{
private int iDocID;
private string sDocNumber;

public int DocID
{
get
{
return iDocID;
}
set
{
iDocID = value;
}
}
public string DocNumber
{
get
{
return sDocNumber;
}
set
{
sDocNumber = value;
}
}
public CDocument()
{
//
// TODO: 在此处添加构造函数逻辑
//
iDocID = 0;
sDocNumber = "";
}
public void SetValue(int fiDocID,string fsDocNumber)
{
iDocID = fiDocID;
sDocNumber = fsDocNumber;
}
}
public class RemoteObject : System.MarshalByRefObject
{
public RemoteObject()
{
//
// TODO: 在此处添加构造函数逻辑
//
Console.WriteLine("实例化RemoteObject对象");
}

~RemoteObject()
{
Console.WriteLine("清除RemoteObject对象");
}

public string ShowMsg(string fsMsg)
{
return "Hello:" + fsMsg;
}
public CDocument SetDocValue(CDocument foDoc)
{
foDoc.SetValue(1234,"cuibw");
return foDoc;
}
}
client.cs:

[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
TcpChannel chan = new TcpChannel();
ChannelServices.RegisterChannel(chan);
RemoteDLL.CDocument foDoc = new RemoteDLL.CDocument();
RemoteDLL.RemoteObject foRemote = (RemoteDLL.RemoteObject)Activator.GetObject(typeof(RemoteDLL.RemoteObject), "tcp://localhost:8086/RemoteObject");
if(foRemote == null && foDoc == null)
{
Console.WriteLine("未找到服务器");
}
foRemote.SetDocValue(foDoc);
}

就在最后一句报错
白掌柜 2003-03-28
  • 打赏
  • 举报
回复
信道 tcp 已注册,同一个信道只能注册一次。跟一下,看看你注册了几次?或是多次调用注册过程?

参考的对象种类不支持尝试的操作。”看看代码才知道。
cbw99 2003-03-28
  • 打赏
  • 举报
回复
citymeteor(流星) :

问题是我不知道该怎么解决啊!!!
白掌柜 2003-03-28
  • 打赏
  • 举报
回复
错误提示里已经写得很明确了。

110,534

社区成员

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

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

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