获取 wcf 服务的已连接客户端列表
如何为服务主机的所有已连接客户端枚举某种位置标识符?我使用双工连接进行长时间运行的计算。服务主机是单例的。
我可以找出(在.net 3.5中)调用客户端的IP,但我不确定如何获取所有连接客户端的IP。
How can I enumerate some sort of location identifier for all of the connected clients for a servicehost? I'm using a duplex connection for long running calculations. The Service host is a singleton.
I can figure out (in .net 3.5) the ip of the calling client but i am unsure how to get the ip of all connected clients.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认情况下,WCF 提倡使用“每次调用”服务,例如您的客户端调用,请求得到处理,然后客户端立即再次断开连接。
WCF 不太适合长时间运行的连接,也不适合长时间运行的连接 - 因此您无法真正“枚举当前连接的用户”,因为没有任何连接(或仅持续一小会儿)。
WCF 不像 Windows 域服务器,您可以在其中登录并长时间保持登录状态。
By default, WCF promotes the use of "per-call" services, e.g. your client calls, the request gets handled, and then the client is disconnected again right away.
WCF doesn't lend itself too well for and isn't intended for long-running connections - so you can't really "enumerate the currently connected users" since there aren't any (or only for a fraction of a second).
WCF is not like a Windows domain server where you log in and stay logged in for an extended period of time.
我不认为有任何内置的东西,但构建一个跟踪 IServiceBehavior + IDispatchMessageInspector 会非常容易,它会在调用分派到服务实现之前检查 RemoteClientEnpointMessageProperty 并将客户端 IP 粘贴到共享列表中,并在通话/会话结束时将其删除。
I don't think there's anything built-in for that, but it'd be pretty easy to build a tracking IServiceBehavior + IDispatchMessageInspector that would inspect the RemoteClientEnpointMessageProperty before the call is dispatched to the service impl and stick the client IP into a shared list, and remove it when the call/session ends.