在 .NET 远程调用期间识别客户端
给定这个 MarshalByRef 类:
public class MyRemotedClass : MarshalByRef
{
public void DoThis()
{
...
}
public void DoThat()
{
...
}
}
客户端代码:
MyRemotedClass m = GetSomehowMyRemotedClass();
m.DoThis();
m.DoThat();
我可以让多个客户端同时执行相同的操作。 我想区分客户。 如何在远程访问的方法内部识别远程调用由谁执行? 例如,我可以记录谁做了什么。 (实际上,我不需要追溯真实的客户端信息,我只是希望能够对客户端的调用进行分组。)
[编辑以添加更多背景信息]
我有大量的代码需要涵盖,包括属性。 因此扩展输入参数列表不是一个选项。
Given this MarshalByRef class:
public class MyRemotedClass : MarshalByRef
{
public void DoThis()
{
...
}
public void DoThat()
{
...
}
}
Client side code:
MyRemotedClass m = GetSomehowMyRemotedClass();
m.DoThis();
m.DoThat();
I can have several clients doing the same thing at a the same time.
I would like to distinct the clients. How can I identify inside the remotely accessed methods, by whom the remoting invocation is executed?
For example, I could log who did what. (Actually, I do not need to trace back the true client info, I just want to be able to group invocations by clients.)
[Edited to add more background info]
I have enormous amount of code to cover, including properties. Therefore extending the input parameter list is not an option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以做的事情之一是通过实现 IServerChannelSinkProvider 来通过 IP 地址识别客户端。
将此类添加到您的远程处理主机项目中:
ClientIPServerSinkProvider.cs
然后,当您启动远程处理主机时,执行如下操作:
在方法调用中,您可以通过执行以下操作来访问客户端的 IP 地址:
One of the things you can do is identify a client by IP address by implementing an
IServerChannelSinkProvider
.Add this class to your remoting host project:
ClientIPServerSinkProvider.cs
Then when you start your remoting host do something like the following:
In your method calls you can access the IP address of the client by doing: