domingo, 15 de septiembre de 2013

CRM 4.0 - Acceso a CRM desde .NET


private CrmService.CrmService GetCrmService(string organizationName) {
        // Setup the Authentication Token
        CrmService.CrmAuthenticationToken token = new CrmAuthenticationToken();
        token.OrganizationName = organizationName;
        CrmService.CrmService crmService = new CrmService.CrmService();
        crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;
        crmService.CrmAuthenticationTokenValue = token;
        return crmService;
}

CrmService.CrmService crmService = GetCrmService(organizationName);
crmService.Credentials = new System.Net.NetworkCredential("usuario", "password", "dominio.com");


--------------------------------------------------------------------------------------------------------------------


/// <summary>
/// Retrieves all the CRM Organizations available on the server
/// </summary>
private void GetOrganizations() {

        //Authenticate with the DiscoveryService using
        //Active Directory Windows Integrated Security
        CrmDiscoveryService.CrmDiscoveryService discoveryService = new CrmDiscoveryService.CrmDiscoveryService();
        //discoveryService.Credentials = System.Net.CredentialCache.DefaultCredentials;
        discoveryService.Credentials = new System.Net.NetworkCredential("usuario","password","dominio.com");
        //Make request for organization information
        RetrieveOrganizationsRequest orgsRequest = new RetrieveOrganizationsRequest();
        RetrieveOrganizationsResponse orgsResponse = (RetrieveOrganizationsResponse)discoveryService.Execute(orgsRequest);

        //Populate the organizations
        for (int i = 0; i < orgsResponse.OrganizationDetails.Length; i++) {
            ddlOrganizations.Items.Add(new ListItem(orgsResponse.OrganizationDetails[i].OrganizationName, orgsResponse.OrganizationDetails[i].OrganizationId.ToString()));
        }
}

No hay comentarios:

Publicar un comentario