none
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

    Arun

    Friday, July 12, 2013 12:30 AM

All replies

  • http://social.msdn.microsoft.com/Forums/vstudio/en-us/d14ce5a6-8428-45f3-9144-8db87ec099f3/how-to-change-wcf-40-server-process-identity-in-webconfig-file-at-windows-xp-iis-v51
    Monday, July 15, 2013 4:55 AM
  • Hi,
    Please try to refer to this: http://forums.asp.net/t/1799882.aspx/1 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
      {
    
        [OperationBehavior(Impersonation=ImpersonationOption.Required)]
        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;
    wcfClient.Hello("...");
    wcfClient.Close();

    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
    Moderator
  • 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

    Thanks

    Arun


    Arun

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

    Of course you can

    Thursday, July 25, 2013 2:14 PM