RetrieveAllEntities Message (MetadataService)

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

Works for all deployment types Works online only

Retrieves the metadata for all entities.

The relevant classes are specified in the following table.

Type Class
Request RetrieveAllEntitiesRequest
Response RetrieveAllEntitiesResponse


To perform this action, the caller must be a user in the organization for which metadata is requested and must have Read Attribute, Read Entity and Read Relationship privileges.


The following example shows how to use the RetrieveAllEntities message.

// Create an authentication token.
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.OrganizationName = "AdventureWorksCycle";

// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0; 

// Create the metadata Web service;
MetadataService metadataService = new MetadataService();
metadataService.Url = "http://<servername>:<port>/MSCRMServices/2007/MetadataService.asmx";
metadataService.CrmAuthenticationTokenValue = token;
metadataService.Credentials = System.Net.CredentialCache.DefaultCredentials;
metadataService.PreAuthenticate = true;

// Create the request
RetrieveAllEntitiesRequest allEntitiesRequest = new RetrieveAllEntitiesRequest();
// Retrieve only the currently published changes, ignoring the changes that have
// not been published.
allEntitiesRequest.RetrieveAsIfPublished = false;
allEntitiesRequest.MetadataItems = MetadataItems.EntitiesOnly;
// Execute the request
RetrieveAllEntitiesResponse allEntitiesResponse = (RetrieveAllEntitiesResponse)metadataService.Execute(allEntitiesRequest);
// Iterate through the retrieved entities
foreach (EntityMetadata entity in allEntitiesResponse.CrmMetadata)
   // Process entity here

[Visual Basic .NET]
' Set up the CRM Service.
Dim token As New CrmAuthenticationToken()
' You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0
token.OrganizationName = "AdventureWorksCycle";

// Create the metadata Web service.
Dim metadataService As New MetadataService ()
metadataService.Url = "http://<servername>:<port>/mscrmservices/2007/MetadataService.asmx";
metadataService.CrmAuthenticationTokenValue = token;
metadataService.Credentials = System.Net.CredentialCache.DefaultCredentials
metadataService.PreAuthenticate = true;

' Create the request.
Dim allEntitiesRequest As New RetrieveAllEntitiesRequest()
allEntitiesRequest.RetrieveAsIfPublished = True
allEntitiesRequest.MetadataItems = MetadataItems.EntitiesOnly

' Execute the request.
Dim allEntitiesResponse As RetrieveAllEntitiesResponse = CType(metadataService.Execute(allEntitiesRequest), RetrieveAllEntitiesResponse)

' Iterate through the retrieved entities.
For Each entity As EntityMetadata In allEntitiesResponse.CrmMetadata
   ' Process entity here
Next entity

See Also


© 2010 Microsoft Corporation. All rights reserved.