我尝试编写一些代码来导入包含 50 多个实体的大型自定义。我使用了 microsoft 文章'ImportXmlWithProgress Message (CrmService)作为基础,但没有得到我期望的输出。
以下代码中的“job.data”与原始 parameterxml 数据没有任何变化。所以这对我来说意味着导入不成功。我使用 microsoft web ui 导入了相同的压缩 importexportxml,它运行良好。所以我想知道为什么我的 job.data 没有更新为每个导入的实体的“结果”属性。
下面是我的导入方法。
private void ImportEntitySchema()
{
const string parameterXml = @"<importexportxml>
<entities>
{0}
</entities>
<nodes/>
<securityroles/>
<settings/>
<workflows/>
</importexportxml>";
var importRequest = new ImportCompressedXmlWithProgressRequest
{
ImportJobId = Guid.NewGuid(),
CompressedCustomizationXml = GetCompressedCustomizationXmlFromEmbeddedResource(),
ParameterXml = string.Format(parameterXml, string.Join("\n", _entitySchemaEntityNames.Select(item => string.Format("<entity>{0}</entity>", item)).ToArray()))
};
try
{
_crmService.Execute(importRequest);
}
catch (Exception e)
{
//Error resulted from import request
}
// Retrieve the results of the import.
XmlNode node;
do
{
Thread.Sleep(2000);
var job = (importjob)_crmService.Retrieve(EntityName.importjob.ToString(), importRequest.ImportJobId, new AllColumns());
var data = new XmlDocument();
data.LoadXml(job.data);
node = data.SelectSingleNode("importexportxml/entities/entity/@result");
} while (node == null);
//code below here never gets executed because the loop continues infinitely
}
我一直在寻找,但在使用 ImportXmlWithProgress 的网络上没有找到任何/许多 [有用的] 示例。希望有人使用过它并且知道如何让它工作。