accessing wcf client identity on service
Asked Answered
C

1

1

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

Capparidaceous answered 5/9, 2011 at 19:55 Comment(0)
C
2

In your server side code, you should be able to retrieve the caller's identity from the security context - something like:

if(ServiceSecurityContext.Current != null &&
   ServiceSecurityContext.Current.PrimaryIdentity != null)
{
   string userName = ServiceSecurityContext.Current.PrimaryIdentity.Name;
}

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 be null for any other authencation mechanism).

Cryostat answered 5/9, 2011 at 20:44 Comment(1)
Hi, Thanks for the reply. I will give a try and let you know If I need more help on this.Capparidaceous

© 2022 - 2024 — McMap. All rights reserved.