locked
CrmDiscoveryService RRS feed

  • Question

  • HI,

    I am developing a web project (CRM 4.0 using asp.net 2.0) and trying to retrieving all organizations using default credentials through
    CrmDiscoveryService, but I was not able to connect to AD.

    If I use CRMService with providing credentials I am able to retrieve data from CRM and also I can access CrmDiscoveryService.Wsdl through IE.

    Could any one help me regarding how to use default credetials using
    CrmDiscoveryService.


    Wednesday, October 15, 2008 4:41 PM

Answers

All replies

  • Take a look at this..

     

     

    Code Snippet

    CrmDiscoveryService discoveryService = new CrmDiscoveryService();
    discoveryService.UseDefaultCredentials = true;
    discoveryService.Url = //Dyscovery Service URL


    RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();
    RetrieveOrganizationsResponse orgResponse =
        (RetrieveOrganizationsResponse)discoveryService.Execute(orgRequest);

     

    OrganizationDetail orgInfo = null;
    foreach (OrganizationDetail orgDetail in orgResponse.OrganizationDetails)
    {
        if (orgDetail.OrganizationName.Equals("NameOfTheOrganization")
        {
            orgInfo = orgDetail;
            break;
        }
    }

    if (orgInfo == null)
        throw new Exception("The organization name is invalid.");


    CrmAuthenticationToken token = new CrmAuthenticationToken();
    token.AuthenticationType = 0;
    token.OrganizationName = orgInfo.OrganizationName;

    CrmService crmService = new CrmService();
    crmService.Url = orgInfo.CrmServiceUrl;
    crmService.CrmAuthenticationTokenValue = token;
    crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;

    crmService.Timeout = -1;
    crmService.PreAuthenticate = true;
    crmService.UnsafeAuthenticatedConnectionSharing = true;

    //Executa a conexao.
    WhoAmIRequest whoRequest = new WhoAmIRequest();

    try
    {
        WhoAmIResponse whoResponse = (WhoAmIResponse)crmService.Execute(whoRequest);
    }

     

     

    Good Luck
    Wednesday, October 15, 2008 4:57 PM
  • Thanks for your reply. I was using same approach but its not working we are using on-premise version of CRM which is configured to use IFD + Windows Authentication.
    Friday, October 17, 2008 6:14 AM
  • Malavika,

    The code written above is meant for On premise authentication, and hence is not working.

    For IFD authentication, CRM requires a CRM Ticket to be sent with every request.

    You can find the exact code snippet at msdn:

    http://msdn.microsoft.com/en-us/library/cc151010.aspx

     

    Hope this helps. Let me know, if you face any issues further. I have worked a lot on CRM Authentication area, and should be able to unblock you.

     

    Monday, October 20, 2008 5:03 PM
  • Nimihas,

    I tried sample code about using the CrmDiscoveryService Web service to obtain organization information. the webservice link "http://server[Stick out tongueort]/MSCRMServices/2007/AD/CrmDiscoveryService.asmx"

    when executing the orgRequest (from below code) came out an error message : "The request failed with HTTP status 401: Unauthorized."
    RetrieveOrganizationsResponse orgResponse = (RetrieveOrganizationsResponse)disco.Execute(orgRequest);

    but when I accessed the CrmDiscoveryService's url manually in IE using domain, username, and the password, it worked fine.

    so i thought 'do i have to put domain and username just like in IFD authentication?'. Then I input the domain and username:
    RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();
    orgRequest.UserId = @"domain\username";
    orgRequest.Password = "password";


    but it remained the same error.

    do you know how to solve this problem?

    thank you
    Tuesday, November 4, 2008 5:02 AM
  • Hi Nimihas,

    I tried the link which you sent before but it didnt worked for me I faced same problem like Cyrene so I used impersonation. I am not sure whether its a better approach or not.
    Tuesday, November 4, 2008 5:27 AM
  • Here's the issue. You are using the web service reference at:

    http://server<port>/MSCRMServices/2007/AD/CrmDiscoveryService.asmx"

     

    Instead, you should be using : http://server<port>/MSCRMServices/2007/SPLA/CrmDiscoveryService.asmx"

     

    Tuesday, November 4, 2008 2:52 PM
  • when i accessed http://server<port>/MSCRMServices/2007/SPLA/CrmDiscoveryService.asmx manually from Internet Explorer, it returns nothing.
    while
    http://server<port>/MSCRMServices/2007/AD/CrmDiscoveryService.asmx shows the CrmDiscoveryService and the Execute service.

    what makes me confused is, if i can see the webservice manually through IE, why can't I accessed the service programmatically..

    any suggestion?

    thank you.
    Wednesday, November 5, 2008 1:50 AM
  • Thank you.
    My problem is solved Big Smile
     
    The problem was, I wrote the code on my computer while the CRM server is on the other computer. So when I accessed the service using Default Credentials, my computer credentials is used.

    Instead of using Default Credentials, I used:

    discoveryService.Credentials = new NetworkCredential("username", "password", "domain");

    And it works!
    No wonder I was able to see the service through IE but unable to access it programmaticaly.
    Thursday, November 6, 2008 1:26 AM