Retrieves all the CRM Organizations available on the server



///
/// Retrieves all the CRM Organizations available on the server
///

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;

//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()));
}
}