代码之家  ›  专栏  ›  技术社区  ›  codewario

检索.NET远程处理客户端的IP信息

  •  1
  • codewario  · 技术社区  · 12 年前

    我需要获得通过.NET远程处理TcpChannel调用函数的客户端的IP地址。我发现 this 这似乎正是我所需要的,然而,我不确定如何使用app.config文件来实现这一点,这是我的项目的要求。我在MSDN上找不到任何关于app.config文件在这种情况下是如何工作的好文档,这可能是因为.NET Remoting是一种遗留技术。有人知道我如何使用app.config文件实现Kev答案第二部分中的配置代码吗?

    在此之前非常感谢您的帮助。

    1 回复  |  直到 12 年前
        1
  •  0
  •   Community CDub    7 年前

    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元素。其他一切都已经作为我们现有的配置存在了。