0

我尝试编写一些代码来导入包含 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 的网络上没有找到任何/许多 [有用的] 示例。希望有人使用过它并且知道如何让它工作。

4

1 回答 1

0

我记得这条消息有问题,我只是不记得到底是什么问题。你的导入文件有多大?我们还制作了一个导入实用程序来导入我们的自定义设置,我在线程上使用ImportCompressedAllXmlRequest同步(无超时) 。BackgroundWorker对于大量自定义,您可能需要查看:http: //support.microsoft.com/kb/918609。为了避免这种情况,我们通常将我们的定制拆分成一堆小的导入。

XPath 应该是"importexportxml/entities/entity[@result]"?

于 2009-10-07T13:12:34.780 回答