检索.NET Remoting客户端的IP信息

时间:2012-10-01 15:39:19

标签: c# .net-4.0 .net-remoting

我需要获取通过.NET Remoting TcpChannel调用函数的客户端的IP地址。我发现this帖子似乎正是我需要的,但是,我不知道如何使用app.config文件来实现它,这是我的项目的要求。我在MSDN上找不到关于app.config文件在这种情况下的工作原理的任何好文档,可能是因为.NET Remoting是一项传统技术。有没有人知道如何使用app.config文件在Kev的答案的第二部分中实现配置代码?

非常感谢您提供任何帮助。

1 个答案:

答案 0 :(得分:0)

This回答给我带来了奇迹。我能够在app.config文件中实现它,如下所示:

<configuration>
   <system.runtime.remoting>
      <application>
         <channels>
            <channel ref="tcp" port="1234">
               <serverProviders>
                  <provider ref="clientinfo" />
                  <formatter ref="binary" />
               </serverProviders>
            </channel>
         </channels>
      </application>
      <channelSinkProviders>
         <serverProviders>
            <provider
               id="clientinfo"
               type="MyNameSpace.ClientInfoServerSinkProvider, MyAssemblyName" />
         </serverProviders>
      </channelSinkProviders>
   </system.runtime.remoting>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

我将整个serverProviders元素添加到tcp通道,并添加了您看到的整个channelSinkProviders元素。其他一切已经存在,作为我们已有的现有配置。