【问题标题】:Test if remoting proxy is valid?测试远程代理是否有效?
【发布时间】: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 上没有运行托管对象的进程(除非有人对我玩刻薄的把戏)所以为什么不抛出异常?

理想情况下,我希望呼叫失败,或者我希望在允许我的客户继续之前通过某种方式测试我的代理是否有效。就像现在一样,无法知道连接是否成功。

【问题讨论】:

    标签: c# proxy remoting


    【解决方案1】:

    也许您可以使用 System.Runtime.Remoting.RemotingServices.IsTransparentProxy(client) 来测试是否设置了 TransparentProxy/RealProxy 链?

    -奥辛

    【讨论】:

      猜你喜欢
      • 2012-08-25
      • 1970-01-01
      • 2011-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-26
      • 2011-12-02
      相关资源
      最近更新 更多