2016-10-03 25 views
0
var importSolutionRequest = new ImportSolutionRequest 
      { 
       ImportJobId = Guid.NewGuid(), 
       CustomizationFile = fileBytes, 
       OverwriteUnmanagedCustomizations = true, 
       PublishWorkflows = true, 
       SkipProductUpdateDependencies = true, 
      }; 
var response = (ImportSolutionResponse)Service.Execute(importSolutionRequest); 

我沒有在此響應對象中獲得任何有用的信息。我應該怎樣做才能在導入解決方案時出現此對象中的警告?我想要在CRM 2016中以編程方式導入解決方案時捕獲所有警告。在響應對象中,我沒有收到任何此類信息

回答

1

你必須查詢ImportJob才能得到你想要的結果(https://msdn.microsoft.com/en-us/library/gg327847.aspx)。

從SDK(https://msdn.microsoft.com/en-us/library/gg509050.aspx):

   // Monitor import success 
       byte[] fileBytesWithMonitoring = File.ReadAllBytes(ManagedSolutionLocation); 

       ImportSolutionRequest impSolReqWithMonitoring = new ImportSolutionRequest() 
       { 
        CustomizationFile = fileBytes, 
        ImportJobId = Guid.NewGuid() 
       }; 

       _serviceProxy.Execute(impSolReqWithMonitoring); 
       Console.WriteLine("Imported Solution with Monitoring from {0}", ManagedSolutionLocation); 

       ImportJob job = (ImportJob)_serviceProxy.Retrieve(ImportJob.EntityLogicalName, impSolReqWithMonitoring.ImportJobId, new ColumnSet(new System.String[] { "data", "solutionname" })); 


       System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); 
       doc.LoadXml(job.Data); 

       String ImportedSolutionName = doc.SelectSingleNode("//solutionManifest/UniqueName").InnerText; 
       String SolutionImportResult = doc.SelectSingleNode("//solutionManifest/result/@result").Value; 

       Console.WriteLine("Report from the ImportJob data"); 
       Console.WriteLine("Solution Unique name: {0}", ImportedSolutionName); 
       Console.WriteLine("Solution Import Result: {0}", SolutionImportResult); 
       Console.WriteLine(""); 

       // This code displays the results for Global Option sets installed as part of a solution. 

       System.Xml.XmlNodeList optionSets = doc.SelectNodes("//optionSets/optionSet"); 
       foreach (System.Xml.XmlNode node in optionSets) 
       { 
        string OptionSetName = node.Attributes["LocalizedName"].Value; 
        string result = node.FirstChild.Attributes["result"].Value; 

        if (result == "success") 
        { 
         Console.WriteLine("{0} result: {1}",OptionSetName, result); 
        } 
        else 
        { 
         string errorCode = node.FirstChild.Attributes["errorcode"].Value; 
         string errorText = node.FirstChild.Attributes["errortext"].Value; 

         Console.WriteLine("{0} result: {1} Code: {2} Description: {3}",OptionSetName, result, errorCode, errorText); 
        } 
       } 
相關問題