首页 > 技术文章 > Remoting在多IP多网卡内外网环境下的问题

yxhblog 2017-08-11 17:24 原文

Remoting服务器端如果服务器有多块网卡,多个IP地址的情况下会出现客户端callback失败的问题,debug以后发现客户端会callback到服务器端另外一个IP地址(例如外网地址,而不是内网地址)。大家知道一般情况下Remoting服务器端的配置方式如下:

<channel ref="tcp" port="55555">

或者用代码的方式:

IDictionary props = new Hashtable();
props["port"= 55555;

IChannel channel = new TcpChannel(props, clientProvider, serverProvider);

该问题有几种解决方案:

 

1. 将Channel绑定到机器名(使用“machineName”),而非IP。但这样要求我们不同网段的客户都能通过同一个DNS名找到这个服务器。 而且使用此属性将覆盖useIpAddress属性设置。

<channel ref="tcp" port="55555" machineName="firewall.yourdomain.com" />

代码方式:

IDictionary props = new Hashtable();
props["port"= 55555;
props["machineName"= "firewall.yourdomain.com";

IChannel channel = new TcpChannel(props, clientProvider, serverProvider);

有关“machineName”属性的详细信息,请查阅MSDN:
http://msdn.microsoft.com/en-us/library/c5zztdc3%28VS.80%29.aspx

 

2.  为服务器每一个IP都开一个Channel,并使用“bindTo”。

     有关bindTo属性的详细定义查看MSDN:specify an IP address of the NIC to bind to when more than one NIC is installed in a machine. This attribute can only be used in the server side.

     配置示例:

<channel ref="tcp" port="55555" bindTo="197.118.137.8">
 <serverProviders>
   <formatter ref="soap" typeFilterLevel="Full" />
   <formatter ref="binary" typeFilterLevel="Full" />
 </serverProviders>
</channel>

3. 通过服务器端的Sink取得Client端的IP,并通过手动配置的类似路由表一样的对应表,通过客户端的IP来选择一个正确的服务器IP。

    我们可以用 TrackingHandler在服务器端Marshal MarshalByRefObject的时候用一个正确的IP。

    实现方法,参考张逸转载的这篇文章:http://www.cnblogs.com/wayfarer/articles/69104.html

推荐阅读