我用Activator.GetObject获得了一个服务器端对象
但是在调用其函数时出现RemotingException:Attempted to call a method declared on type 'ServerApplication.ServerInitor' on an object which exposes 'ServerApplication.UserMgr'.客户端代码:public void Logon()
{
ServerApplication.ServerInitor server =
(ServerApplication.ServerInitor)Activator.GetObject(typeof(ServerApplication.ServerInitor), "tcp://192.168.0.4:2739/chat");
server.Log_on("a"); //该函数报异常
}
服务器端代码:
public class ServerInitor: MarshalByRefObject
{
private UserMgr userManager;
//中间代码略 public Guid Log_on(string nick)
{
return userManager.Logon(nick);
} public void Log_off(Guid guid)
{
userManager.Logoff(guid);
} public void Say(String guid, String content)
{
userManager.Say(guid, content);
}
但是在调用其函数时出现RemotingException:Attempted to call a method declared on type 'ServerApplication.ServerInitor' on an object which exposes 'ServerApplication.UserMgr'.客户端代码:public void Logon()
{
ServerApplication.ServerInitor server =
(ServerApplication.ServerInitor)Activator.GetObject(typeof(ServerApplication.ServerInitor), "tcp://192.168.0.4:2739/chat");
server.Log_on("a"); //该函数报异常
}
服务器端代码:
public class ServerInitor: MarshalByRefObject
{
private UserMgr userManager;
//中间代码略 public Guid Log_on(string nick)
{
return userManager.Logon(nick);
} public void Log_off(Guid guid)
{
userManager.Logoff(guid);
} public void Say(String guid, String content)
{
userManager.Say(guid, content);
}
解决方案 »
- reportviewer 动态添加 行列
- 用递归求值,算法题,用兴趣的来接龙
- 求助~~~~~~~~~关于OnPaint()和Form1_Paint()的区别
- 网站建设:session,application和request
- c#中控件中的事件不能靠最上面的“常规”“声明”栏选么??
- 求教:关于Outlook中当前用户的email地址问题
- 定义方法的问题!
- 水晶报表能实现这样的功能吗
- 关于水晶报表:VS.NET2002、2003自带的版本是多少?BC#B有没有自带水晶报表?
- 各位大哥推荐几本C#的好书吧?说者有分!
- 关于使用线程实现显示系统时间的问题
- combobox里面 数字如何按从小到大的排列
ServerApplication.ServerInitor server =
(ServerApplication.ServerInitor)Activator.GetObject(typeof(ServerApplication.ServerInitor), "tcp://192.168.0.4:2739/ServerInitor.Rem");
//仅供参考
/* -------- server -------- */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Services;
using System.Runtime.Remoting.Channels.Tcp;
using Test04_Demo;try
{
IDictionary ports = new Hashtable();
ports["port"] = 8100;
BinaryClientFormatterSinkProvider cs = new BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider ss = new BinaryServerFormatterSinkProvider();
//TcpChannel channel = new TcpChannel(ports, cs, ss);
channel = new TcpChannel(ports, cs, ss);
ChannelServices.RegisterChannel(channel, false);
Demo demo = new Demo();
RemotingServices.Marshal(demo, "test04_demo.soap");
lblOne.Text = "好极了,1号服务启动成功!";
}
catch
{
lblOne.Text = "因网络或其他故障,未能成功启动服务";
}/* -------- client ----------*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Test04_Demo;try
{
demo = (Demo)Activator.GetObject(typeof(Demo), "tcp://localhost:8100/test04_demo.soap");
if (demo != null)
{
lblInfo.Text = "恭喜,已经连接成功";
}
}
catch
{
lblInfo.Text = "抱歉,因故未能连接上";
}
OK,散分