locked
Unable to get the Correct User from WhoAmIRequest RRS feed

  • Question

  • Hi All,

    I am unable to get the correct userid from WhoAmIResponse object after making a WhoAmIRequest to CrmService. IFD is enabled on the CRM installation I am interacting with.

    I have been following this msdn resource for authentication from an Aspx page as this resembles my scenario

    The scenario I am dealing with is given below:

    I have web service hosted in a sub directory of ISV directory of Dynamics CRM website. This web srvice of mine calls CrmService for WhoAmIRequest using the following code 
                    using (new Microsoft.Crm.Sdk.CrmImpersonator())
                    {
                        Microsoft.Crm.Sdk.CrmAuthenticationToken token =
                            Microsoft.Crm.Sdk.CrmAuthenticationToken.ExtractCrmAuthenticationToken(context, "orgName");
                        token.OrganizationName = "orgName";
                        token.AuthenticationType = 0;
                        Microsoft.Crm.SdkTypeProxy.CrmService crmService = new Microsoft.Crm.SdkTypeProxy.CrmService();
                        crmService.CrmAuthenticationTokenValue = token;
                        crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;
                        crmService.Url = System.Configuration.ConfigurationManager.AppSettings["CrmServiceUrl"];
                        Microsoft.Crm.SdkTypeProxy.WhoAmIRequest userRequest = new Microsoft.Crm.SdkTypeProxy.WhoAmIRequest();
                        Microsoft.Crm.SdkTypeProxy.WhoAmIResponse user =
                            (Microsoft.Crm.SdkTypeProxy.WhoAmIResponse)crmService.Execute(userRequest);
                        id = user.UserId;
                    }
    
    This webservic of mine is called from a silverlight control hosted in an IFrame of some entity's form. What I want is to get the actual user who initiated the call by clicking on some button etc. on that silverlight control that in turn calls the web service. 
    What I get is a UserId of System user which I have seen is some system user which is not even shown on the Settings>user view of CRM application.

    Any idea why this is happening and how can I solve this.

    Best Regards,
    Haris Munawar
    Friday, May 8, 2009 11:26 AM

Answers

  • Hi, Haris.

    To retrieve running user id i use following code:

    Guid UserId = Guid.Empty;
    using
     (new
     CrmImpersonator())
    {
          CrmAuthenticationToken token = CrmAuthenticationToken.ExtractCrmAuthenticationToken(Context, <OrgName>);
          UserId = token.CallerId;
    }
    
    

    Истина открывается подготовленному уму. Мой блог - http://a33ik.blogspot.com
    • Marked as answer by HarisM Friday, May 8, 2009 11:58 AM
    Friday, May 8, 2009 11:33 AM
    Moderator

All replies

  • Hi, Haris.

    To retrieve running user id i use following code:

    Guid UserId = Guid.Empty;
    using
     (new
     CrmImpersonator())
    {
          CrmAuthenticationToken token = CrmAuthenticationToken.ExtractCrmAuthenticationToken(Context, <OrgName>);
          UserId = token.CallerId;
    }
    
    

    Истина открывается подготовленному уму. Мой блог - http://a33ik.blogspot.com
    • Marked as answer by HarisM Friday, May 8, 2009 11:58 AM
    Friday, May 8, 2009 11:33 AM
    Moderator
  • Hi a33ik,

    Thanks a lot, It worked

    Regards,
    Haris Munawar
    Friday, May 8, 2009 11:59 AM