Saturday, May 23, 2015

CRM 2013 - ExecuteAsync Importing large or Complex solutions

In Dynamics CRM 2011 you were only able to import solutions synchronously. This means that the caller had to wait until the solution import process completes. This resulted in time out errors when importing large or complex solutions. Customers had to increase their time out settings significantly for on-premise deployments.

In Dynamics CRM 2013, the “ExecuteAsync” message solves this problem. 

I implemented for this post an example that show this functionality through a console application.
// Comment
static void Main(string[] args)
        {
            #region console in
            Console.WriteLine("---------------IMPORT ASYC SOLUTION CRM 2013 -------------------");
            Console.WriteLine(" v 1.0                                                          ");
            Console.WriteLine(" Autore: Nicola Grillo                                          ");
            Console.WriteLine(" ModifiedOn: 24/05/2015                                         ");
            Console.WriteLine("----------------------------------------------------------------");
            Console.WriteLine("");
            Console.WriteLine("");
            var esempioURL = "Url=http://XXXXXXXXX/yyyy; Domain=XXXXXX; Username=n.grillo; Password=XXXX001;";
            Console.WriteLine("(I) INSERIRE LA STRINGA DI CONNESSIONE CRM");
            Console.WriteLine("");
            Console.WriteLine("(I) ESEMPIO: " + esempioURL);
            Console.WriteLine("");
            Console.WriteLine("");
            var consoleConnectionString = ReadFromConsole(""); 
            Console.WriteLine("");
            Console.WriteLine("");
            var esempioPath = "C:\\Users\\n.grillo\\Desktop\\DynamicsCRMEasySolutionImporter_1_0_0_0.zip";
            Console.WriteLine("(I) INSERIRE IL PATH DELLA SOLUTION");
            Console.WriteLine("");
            Console.WriteLine("(I) ESEMPIO: " + esempioPath);
            Console.WriteLine("");
            Console.WriteLine("");
            var consolePathSolution = ReadFromConsole("");
            #endregion

            var connection = CrmConnection.Parse(consoleConnectionString);
            var service = new OrganizationService(connection);
            var context = new CrmOrganizationServiceContext(connection);
            
            IOrganizationService sdk = (IOrganizationService)context;
            ExecuteAsyncRequest request = new ExecuteAsyncRequest
            {
                Request = new ImportSolutionRequest
                {
                    CustomizationFile = File.ReadAllBytes(consolePathSolution),
                    PublishWorkflows = true,
                }
            };
            
            ExecuteAsyncResponse response = (ExecuteAsyncResponse)sdk.Execute(request);
            
            #region console
            Console.WriteLine("");
            Console.WriteLine("");
            Console.WriteLine("Importazione inviata con successo");
            Console.ReadKey();
            #endregion
        }

        const string _readPrompt = "Dynamics CRM 2013 console> ";
        public static string ReadFromConsole(string promptMessage)
        {
            // Show a prompt, and get input:
            Console.Write(_readPrompt);
            
            return Console.ReadLine();
        }


Here you can find the result Console Application

Nicola Grillo

1 comment: