Webservice as SYSTEM RRS feed

  • Question

  • Hello,

    I developed a asp.net page using crm data but i have an authentification problem.
    When i'm running my page in local(using Visual Studio), i'm connected as me.
    But when i'm running the same page on the server i'm all the time connected as SYSTEM.

    Here is my code:

    CLASS : ServiceManagement2
    CONTRUCTOR = ServiceManagement2()
    CrmAuthenticationToken token = new CrmAuthenticationToken();
    token.AuthenticationType = 0; 
    token.OrganizationName = "MYORG";
    this.Service = new CrmService.CrmService();
    Service.Url= "http://nsilas07/mscrmservices/2007/crmservice.asmx";
    Service.CrmAuthenticationTokenValue = token;
    Service.Credentials = System.Net.CredentialCache.DefaultCredentials;
    ServiceManagement2 sm = new ServiceManagement2();
    WhoAmIRequest req = new WhoAmIRequest();
    var response = sm.Service.Execute(req) as WhoAmIResponse;
    string bu = response.UserId.ToString();
    return bu;

    Thank you in advance.

    Monday, May 27, 2013 10:38 AM


All replies

  • Hi,

    This is because you are using 'DefaultCredentials' which will authenticate as the user context that the webservice is running under. If you want to 'impersonate' another user, you will need to set the CallerID - see http://msdn.microsoft.com/en-gb/library/gg334744.aspx


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Proposed as answer by Philippe LEAL Monday, May 27, 2013 12:11 PM
    • Marked as answer by KMAREC Wednesday, May 29, 2013 8:16 AM
    Monday, May 27, 2013 12:10 PM
  • Where are you deploying the ASP .Net application - within the Crm website, or in a different website ?

    If you want to impersonate the calling user (assuming they are a CRM user), the techniques are different depending on where you deploy the application:

    • If it's within the Crm website, use the CrmImpersonator class - http://mscrmuk.blogspot.co.uk/2010/11/how-to-use-impersonation-in-asp-net.html 
    • If it's in a different website, then CrmImpersonator won't work. AD impersonation should be possible, though you'll need to configure it within your web.config. You may also need to enable delegation in AD if the ASP .Net application is on a different server to CRM

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Tuesday, May 28, 2013 5:17 AM