Export (0) Print
Expand All

On-Premise Authentication

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

On-premise authentication with Active Directory is shown in the following figure.

Active Directory Authentication

The CrmDiscoveryService Web service is accessed through a global URL of an on-premise Microsoft Dynamics CRM server. Each Microsoft Dynamics CRM server hosts the CrmDiscoveryService Web service, which is located here: http://<server:port>/MSCRMServices/2007/AD/CrmDiscoveryService.asmx

For on-premise authentication, you can also use the CrmDiscoveryService to obtain a name and URL endpoint for a target organization by using the RetrieveOrganizationsRequest. If you already know the name and endpoint URL for a target organization in a Microsoft Dynamics CRM installation, you would use the organization name and URL to configure the CrmService instance and then call CrmService Web methods.

The following code sample shows you how to obtain organization information from the CrmDiscoveryService Web service and call a CrmService method.

[C#]
// STEP 1: Instantiate and configure the CrmDiscoveryService Web service.
CrmDiscoveryService discoveryService = new CrmDiscoveryService();
discoveryService.UseDefaultCredentials = true;
discoveryService.Url = "http://localhost/MSCRMServices/2007/AD/CrmDiscoveryService.asmx";

// STEP 2: Retrieve the desired organization name and endpoint URL from the
// CrmDiscoveryService Web service.
RetrieveOrganizationsRequest orgRequest = new RetrieveOrganizationsRequest();
RetrieveOrganizationsResponse orgResponse =
    (RetrieveOrganizationsResponse)discoveryService.Execute(orgRequest);

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

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

// STEP 3: Create and configure an instance of the CrmService Web service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0; // See Microsoft.Crm.Sdk.AuthenticationType
token.OrganizationName = orgInfo.OrganizationName;

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

// STEP 4: Invoke a CrmService Web service method.
WhoAmIRequest whoRequest = new WhoAmIRequest();
WhoAmIResponse whoResponse = (WhoAmIResponse)crmService.Execute(whoRequest);

A complete code sample, which demonstrates Active Directory authentication, can be found in the SDK\Walkthroughs\Authentication\CS|VB\ActiveDirectory folder of the SDK samples.

See Also

Concepts

Tasks

Other Resources


© 2010 Microsoft Corporation. All rights reserved.


Show:
© 2014 Microsoft