访问服务上的 WCF 客户端身份
经过几个 WCF 教程后,我可以开发一个 WCF 客户端/服务器应用程序,服务和客户端应用程序都是 Windows 窗体应用程序。我可以通过指定用户名和密码来使用每个客户端调用服务。我的 WCF 服务应用程序还显示所有连接的客户端及其用户名。但是,当多个客户端向服务发送请求时,我无法识别哪个用户调用了该方法。这很重要,因为我的应用程序往往为每个客户端处理都有自己的会话,就像任何常规 ASP.NET 应用程序一样。每个用户都有自己的身份和自己的应用程序域。
此外,我希望我的服务将消息发送回客户端,因此我实现了回调合约。此外,我使用 netTcpBinding 因为我的应用程序需要在我的 Intranet 上运行。
如何在 WCF 客户端/服务器应用程序中实现此场景?
有什么帮助吗?
谢谢
谢谢你之前的回复。这对我真的很有帮助。 现在,如果我想使用用户名和密码进行自定义身份验证该怎么办? 假设我有 50 个具有有效用户名和密码的客户端。如何获取在特定时间点调用服务方法的客户端(这 50 个)的身份?
谢谢
After couples of WCF tutorials, I could develop a WCF client/Server application, both service and client applications are Windows Forms Application. I can call service using each client by specifying UserName and password. My WCF service applications also shows all the connected clients with their username as well. But, When multiple clients send a request to service then I'm not being able to identity which user has called the method. This is important as my application tend to have its own session for each client processing, just as any regular ASP.NET application has. Each user have their own Identity and its own Application Domain.
Moreover, I want my service to send messages back to client, so I have implemented callback contract. In addition, I'm using netTcpBinding as my applications need to run on my intranet.
How can I implement this scenario in WCF client/server application ?
Any help please ??
Thanks
Thanks for your previous reply. Its really helpful to me.
Now, What If I want to use custom authentication using username and password.
Lets assume that I have 50 clients with valid username and password. How can I get an identity of a client (out of those 50) whose is invoking a service method at a particular point of time ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在服务器端代码中,您应该能够从安全上下文中检索调用者的身份 - 类似于:
如果您使用 Windows 身份验证调用服务(这也可能适合您 - 如果您在公司 LAN 上,看起来) - 您应该能够访问安全上下文的
.WindowsIdentity
(对于任何其他身份验证机制,这将是null
)。In your server side code, you should be able to retrieve the caller's identity from the security context - something like:
If you're calling a service with Windows authentication (which might also work for you - if you're on a corporate LAN, as it would seem) - you should be able to access the security context's
.WindowsIdentity
instead (this will benull
for any other authencation mechanism).