RetrieveAttribute Message (MetadataService)
![]() |
[Applies to: Microsoft Dynamics CRM 4.0]
| Works for all deployment types | Works online only |
Retrieves the metadata for the specified attribute.
The relevant classes are specified in the following table.
| Type | Class |
| Request | RetrieveAttributeRequest |
| Response | RetrieveAttributeResponse |
Remarks
To perform this action, the caller must be a user in the organization for which metadata is requested and must have Read Attribute privilege.
Example
The following example shows how to use the RetrieveAttribute message.
[C#] // 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. RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest(); attributeRequest.EntityLogicalName = EntityName.contact.ToString(); attributeRequest.LogicalName = "fullname"; // Retrieve only the currently published changes, ignoring the changes that have // not been published. attributeRequest.RetrieveAsIfPublished = false; RetrieveAttributeResponse attributeResponse = (RetrieveAttributeResponse)metadataService.Execute(attributeRequest); // Access the retrieved attribute. StringAttributeMetadata retrievedAttributeMetadata = (StringAttributeMetadata)attributeResponse.AttributeMetadata;
[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 attributeRequest As New RetrieveAttributeRequest() attributeRequest.EntityLogicalName = EntityName.contact.ToString() attributeRequest.LogicalName = "fullname" attributeRequest.RetrieveAsIfPublished = True Dim attributeResponse As RetrieveAttributeResponse = CType(metadataService.Execute(attributeRequest), RetrieveAttributeResponse) ' Access the retrieved attribute. Dim retrievedAttributeMetadata As StringAttributeMetadata = CType(attributeResponse.AttributeMetadata, StringAttributeMetadata)
See Also
Reference
© 2010 Microsoft Corporation. All rights reserved.
