【发布时间】:2023-03-26 08:47:01
【问题描述】:
我在客户端和服务器之间使用远程处理,当它工作时,我看到了一些我不理解的行为。
我的服务器设置如下:
BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
IDictionary props = new Hashtable();
props["name"] = "MarsLogServer.rem";
props["port"] = Properties.Settings.Default.ListeningPort;
props["useIpAddress"] = false;
server = new LogServer();
chan = new TcpChannel(props, clientProv, serverProv);
ChannelServices.RegisterChannel(chan, true);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(LogServer), "MarsLogServer.rem", WellKnownObjectMode.Singleton);
我的客户端连接如下:
this.logServer = (ILogServer)Activator.GetObject(typeof(ILogServer), connectForm.Url);
this.logServer.AttachClient(this, connectForm.SessionKey)
发生的事情是我什至没有运行服务器,但是我在客户端接收到的代理上调用 AttachClient() 成功。我不明白为什么会这样,在提供的 URL 上没有运行托管对象的进程(除非有人对我玩刻薄的把戏)所以为什么不抛出异常?
理想情况下,我希望呼叫失败,或者我希望在允许我的客户继续之前通过某种方式测试我的代理是否有效。就像现在一样,无法知道连接是否成功。
【问题讨论】: