When you try to execute RetrieveAllEntitiesRequest to retrieve metadata for all the entities in your organisation you may receive the following error: “Message: The request channel timed out while waiting for a reply after 00:01:59.7655710. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout.” Because of the large amount of data retrieved when executing RetrieveAllEntitiesRequest the default timeout value of 2 minutes is unlikely to be enough.
To increase the timeout value you need to set the timeout property on the OrganizationServiceProxy object. If you use the OrganizationServiceContext (as generated by CrmSvcUtil) you have to set the timeout on the OrganizationServiceProxy object you pass into the OrganizationServiceContext as there is no way to set the Timeout directly for the OrganizationServiceContext.
Of course timeouts can happen when you are doing other requests as well (and the solution is the same), but it is highly likely you’ll run into your first timeout issue when you start playing with the RetrieveAllEntitiesRequest request.
- using System;
- using System.Linq;
- using System.Net;
- using System.ServiceModel.Description;
- using Microsoft.Xrm.Sdk.Client;
- using Microsoft.Xrm.Sdk.Messages;
- using Microsoft.Xrm.Sdk.Metadata;
- namespace MetadataConsoleApplication
- {
- class Program
- {
- static void Main(string[] args)
- {
- var organizationUrl
- = string.Format(
- “{0}/{1}/XRMServices/2011/Organization.svc”,
- “http://{your_ip}”, “{organization_name}”);
- var credentials = new ClientCredentials();
- credentials.Windows.ClientCredential
- = new NetworkCredential(
- “{username}”, “{password}”, “{domain}”);
- var serviceProxy
- = new OrganizationServiceProxy(
- new Uri(organizationUrl), null,
- credentials, null);
- serviceProxy.ServiceConfiguration
- .CurrentServiceEndpoint.Behaviors.Add(
- new ProxyTypesBehavior());
- // Increase the timeout to 30 minutes
- // so the operation succeeds
- serviceProxy.Timeout = new TimeSpan(0, 0, 30, 0);
- var context = new AcmeContext(serviceProxy);
- // Retrieve metadata from CRM
- var request = new RetrieveAllEntitiesRequest
- {
- EntityFilters = EntityFilters.All,
- RetrieveAsIfPublished = true,
- };
- var response
- = (RetrieveAllEntitiesResponse)
- context.Execute(request);
- Console.WriteLine(
- “Entities retrieved: “
- + response.EntityMetadata.Count());
- Console.ReadKey();
- }
- }
- }