How do i get the WindowsIdentity object in WCF service RRS feed

  • Question

  • Hi,

    My application is windows application(smart client) and i have  WCF services.

    application is running in different domain(customer evironement) and service is hosted in some other domain(our environment)

    Now the problem is how do i get the security context from wcf request.(service end)

    Please guide me

    Advance Thanks


    Friday, July 12, 2013 12:30 AM

All replies

    Monday, July 15, 2013 4:55 AM
  • Hi,
    Please try to refer to this: with the following:

    If you want to impersonate get the WindowsIdentity object in WCF, use a binding that uses Windows authentication and creates a session such as NetTcpBinding or WSHttpBinding. Then you apply the OperationBehaviorAttribute to the service method that requires impersonation and set the Impersonation property to Required:

    public class HelloService : IHello
        public string Hello(string s)
     string calledBy = Thread.CurrentPrincipal.Identity.Name;

    From your client you then set the client credentials to permit impersonation:

    SampleHelloClient wcfClient = new SampleHelloClient();
    wcfClient.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;

    Hope it can help you.

    Best Regards.

    Amy Peng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 16, 2013 7:54 AM
  • Hi,

    i believe this will work for me . i have one question here

    whatever you suggested will work for cross domain meaning the client is running in x domain and server is running in y domain and can i get the identity(wcf request) of client which is running in x domain

    Please reply as soon as possible




    Saturday, July 20, 2013 12:21 AM
  • Hi,

    Of course you can

    Thursday, July 25, 2013 2:14 PM