测试远程代理是否有效?

发布于 2024-10-08 07:35:29 字数 1273 浏览 0 评论 0原文

我在客户端和服务器之间使用远程处理,虽然它有效,但我看到了一些我不理解的行为。

我的服务器设置如下:

        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 上运行托管对象(除非有人对我玩卑鄙的把戏),那么为什么它不抛出异常呢?

理想情况下,我希望调用失败,或者我想要某种方法来测试我的代理是否有效,然后再允许我的客户端继续。现在无法知道连接是否成功。

I'm using remoting between a client and server, and while it works, I'm seeing some behavior I don't understand.

I'm setting up my server as follows:

        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);            

And my client is connecting as follows:

this.logServer = (ILogServer)Activator.GetObject(typeof(ILogServer), connectForm.Url);
this.logServer.AttachClient(this, connectForm.SessionKey)

What's happening is I don't even have the server running, but my call to AttachClient() on the proxy my client receives succeeds. I don't understand why that is, there's no process running hosting an object on the provided URL (unless someone is playing a mean trick on me) so why doesn't it throw an exception?

Ideally I'd like the call to fail, or I'd like some way to test that my proxy is valid before allowing my client to proceed. As it is now there's no way of knowing if the connection was successful or not.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

硬不硬你别怂 2024-10-15 07:35:29

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

-奥辛

Maybe you could use System.Runtime.Remoting.RemotingServices.IsTransparentProxy(client) to test if the TransparentProxy/RealProxy chain is set up?

-Oisin

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文