.Net Remoting:指示用于连接到一台服务器的本地接口 [英] .Net Remoting: Indicate which local interface to use to connect to one server

查看:161
本文介绍了.Net Remoting:指示用于连接到一台服务器的本地接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个与.Net远程连接的服务器。

We have a server which we connect with .Net remoting.

该服务器位于两个网络中,客户端位于两个网络中。客户端和服务器只有一个公用网络:

The server is on two network, the client is on two network. The client and the server have only one network in common:

使用发现,我们找到了IP服务器的服务器(在这种情况下:10.10.10.110)。我们创建 TcpChannel 并连接到服务器。

Using discovery, we find the IP of the server(in this case: 10.10.10.110). We create the TcpChannel and we connect to the server.

服务器接收到呼叫,但是当它尝试向客户端发送一些信息。我们得到一个例外,说我们试图将数据发送到无法到达的IP(10.12.10.100)。

The server receives the calls, but when it tries to send some information to the client sink. we get an exception saying that we tried to send data to an unreacheable IP(10.12.10.100).

因此服务器正确地宣布了他的地址,但是我们如何指示客户端使用特定IP的网络接口?

So the server is announcing correctly his address, but how can we indicate to the client to use the network interface with a specific IP?

某些代码:

客户端,初始化:

IDictionary tcpChannelConfiguration = new Hashtable();
string instanceName = "RemotingClient" + Utils.GenerateRandomString(5);
tcpChannelConfiguration["name"] = instanceName);
tcpChannelConfiguration["port"] = 0;
tcpChannelConfiguration["machineName"] = m_interfaceToHost;//This is containing the local interface to use
tcpChannelConfiguration["bindTo"] = m_interfaceToHost;
IClientChannelSinkProvider formatClient = new BinaryClientFormatterSinkProvider(tcpChannelConfiguration, null);
IClientChannelSinkProvider identityFormatClient = new IdentityClientSinkProvider{Next = formatClient};
BinaryServerFormatterSinkProvider formatServer = new BinaryServerFormatterSinkProvider(tcpChannelConfiguration, null)
{TypeFilterLevel = TypeFilterLevel.Full};
m_channel = new TcpChannel(tcpChannelConfiguration, identityFormatClient, formatServer);
ChannelServices.RegisterChannel(m_channel, false);

//Then we get the remote object:
IServer server  = (IServer)Activator.GetObject(typeof(IServer), String.Format("tcp://{0}:{1}/{2}", m_ipAddress, m_port, instanceName));
[...]

这是我在服务器端遇到的例外情况:

Here is the exception I'm having server side:

System.Net.Sockets.SocketException (0x80004005): A socket operation was attempted to an unreachable network 10.12.10.100:54330

Server stack trace: 
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
   at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket(EndPoint ipEndPoint)
   at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket()
   at System.Runtime.Remoting.Channels.RemoteConnection.GetSocket()
   at System.Runtime.Remoting.Channels.SocketCache.GetSocket(String machinePortAndSid, Boolean openNew)
   at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.SendRequestWithRetry(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream)
   at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream)
   at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)

如何向客户端指示必须向服务器提供哪个IP /接口?

How can I indicate to the client which IP/interface it has to provide to the server?

通过提供自定义 ClientSinkProvider ?

编辑

我发现了可能会引起兴趣的事情,我注意到对于简单的查询响应,.Net Remoting可以正常工作,但是对于其中某些查询,查询提供了一个对象,该对象将被服务用作回调,在这种情况下,它不起作用。

I found something that might be interessting, I noticed that for simple Query-response, the .Net Remoting is working fine, but for some of them, the query gives a object that will be used as callback by the service, and in this case, it is not working.

我刚刚获得了.Net的源代码来检查此操作是如何完成的,但是我没有发现还没有为相反的对象创建代理

I just got the source code of .Net to check how this is done, but I didn't found YET the creation of the proxy for the opposite direction.

虽然拥有TcpChannel的源代码,但我看到在某些时候,该方法在服务器端(它将建立与回调的连接)。客户)收到标头中具有正确的远程IP的请求,但以URI中的IP错误而结束:

While having the source code of the TcpChannel, I see that at some point, the method, on the server side(which will establish a connection to the callback on the client) receives the request with the correct remote IP in the header, but ends by having the wrong IP in the URI:

推荐答案

几年前,我写了一些远程应用程序,即使我没有得到这个确切的错误,我的理解是服务器试图通过连接回服务器返回结果。客户端,但是使用了错误的IP。

I wrote a couple of remoting apps years ago, and even though I didn't get this exact error, my understanding is that the server tries to return results by connecting back to the client, but then using the wrong IP.

如果您明确指定客户端用于与服务器通信的IP,会发生什么?尝试将以下内容添加到客户端.config文件中:

What happens if you explicitly specify the IP the client shall use for the communication with the server? Try adding the following to your clients .config file:

<configuration>
    <system.runtime.remoting>
        <application>
            <channels>
                <channel ref="tcp" port="0" bindTo="10.10.10.100" />
            </channels>
        </application>
    </system.runtime.remoting>
</configuration>

这应确保连接和流量通过请求的IP路由-而不是使用10.12。 10.100连接[如果该网络在没有通过10.10.xx的情况下达到10.11.xx的水平,则可能会正常工作]。

This should ensure that the connection and traffic is routed through the requested IP - and not by using 10.12.10.100 to connect [this might accually work if that network have some mean to reach 10.11.x.x without passing 10.10.x.x].

这篇关于.Net Remoting:指示用于连接到一台服务器的本地接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆