Export (0) Print
Expand All
Expand Minimize

ImportCompressedXmlWithProgress Message (CrmService)

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Works for all deployment typesWorks online only

Import specified customizations, with progress logging, from an XML file that has been compressed using the WinZip format.

The relevant classes are specified in the following table.

TypeClass
RequestImportCompressedXmlWithProgressRequest
ResponseImportCompressedXmlWithProgressResponse

Remarks

The success or failure of the import operation is recorded in the import job entity.

To use this message, pass an instance of the ImportCompressedXmlWithProgressRequest class as the request parameter in the Execute method.

For a list of required privileges, see ImportCompressedXmlWithProgress privileges.

Example

This request requires an ImportExportXml file for import. This example exports this file from CRM and then imports it back into Microsoft Dynamics CRM.

[C#]
// Set up the CRM service.
CrmAuthenticationToken token = new CrmAuthenticationToken();

// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0; 
token.OrganizationName = "AdventureWorksCycle";
 
CrmService service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Get a customization xml document by exporting one.
ExportCompressedXmlRequest exportRequest = new ExportCompressedXmlRequest();
exportRequest.EmbeddedFileName = "Customizations.xml";
exportRequest.ParameterXml =
    @"<importexportxml>
        <entities>
            <entity>account</entity>   
        </entities>
        <nodes/>
        <securityroles/>
        <workflows/>
        <settings/>
    </importexportxml>";

ExportCompressedXmlResponse exportResponse = (ExportCompressedXmlResponse)service.Execute(exportRequest);

// Create a ImportCompressedXmlWithProgressRequest Request.
ImportCompressedXmlWithProgressRequest request = new ImportCompressedXmlWithProgressRequest();

// Set the customization zip file to import.
request.CompressedCustomizationXml = exportResponse.ExportCompressedXml;

// Set the ParameterXml, which defines what customizations to import.
request.ParameterXml =
    @"<importexportxml>
        <entities>
            <entity>account</entity>   
        </entities>
        <nodes/>
        <securityroles/>
        <workflows/>
        <settings/>
    </importexportxml>";

// Give the request a unique import Job Id.
request.ImportJobId = Guid.NewGuid();

// Execute the request. 
ImportCompressedXmlWithProgressResponse response = (ImportCompressedXmlWithProgressResponse)service.Execute(request);

// Retrieve the results of the import.
// Be aware that using AllColumns may adversely affect
// performance and cause unwanted cascading in subsequent 
// updates. A best practice is to retrieve the least amount of 
// data required.
importjob job = (importjob)service.Retrieve(EntityName.importjob.ToString(), request.ImportJobId, new AllColumns());
XmlDocument data = new XmlDocument();
data.LoadXml(job.data);

// See if the result of the first entity was successful
XmlNode node = data.SelectSingleNode("importexportxml/entities/entity/@result");
if (node.Value != "success")
{
    success = false;
}
if (success)
{
   // Publish the imported customizations.
   PublishXmlRequest publishXmlRequest = new PublishXmlRequest();

   publishXmlRequest.ParameterXml = customizationXML;

   // Execute the publish request.
   service.Execute(publishXmlRequest);
}
[Visual Basic .NET]
' Set up the CRM service.
Dim token As New CrmAuthenticationToken()
' You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0
token.OrganizationName = "AdventureWorksCycle";
 
Dim service As New CrmService()
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials

' Get a customization xml document by exporting one.
Dim exportRequest As New ExportCompressedXmlRequest()
exportRequest.EmbeddedFileName = "Customizations.xml"
exportRequest.ParameterXml = "<importexportxml>" & ControlChars.CrLf & "<entities>" & ControlChars.CrLf & "<entity>account</entity>   " & ControlChars.CrLf & "</entities>" & ControlChars.CrLf & "<nodes></nodes>" & ControlChars.CrLf & "<securityroles></securityroles>" & ControlChars.CrLf & "<workflows></workflows>" & ControlChars.CrLf & "<settings></settings>" & ControlChars.CrLf & "</importexportxml>"
Dim exportResponse As ExportCompressedXmlResponse = CType(service.Execute(exportRequest), ExportCompressedXmlResponse)

' Build XML string that defines what customization to export and publish.
Dim customizationXML As String = "<importexportxml>" & ControlChars.CrLf & "<entities>" & ControlChars.CrLf & "<entity>account</entity>   " & ControlChars.CrLf & "</entities>" & ControlChars.CrLf & "<nodes></nodes>" & ControlChars.CrLf & "<securityroles></securityroles>" & ControlChars.CrLf & "<workflows></workflows>" & ControlChars.CrLf & "<settings></settings>" & ControlChars.CrLf & "</importexportxml>"

' Create a ImportCompressedXmlWithProgressRequest request.
Dim request As New ImportCompressedXmlWithProgressRequest()

' Set the customization zip file to import.
request.CustomizationXml = System.IO.File.ReadAllBytes("C:\Customizations.zip")

' Set the ParameterXml which defines what cusomization to export.
request.ParameterXml = customizationXML

' Give the request a unique import Job ID.
request.ImportJobId = Guid.NewGuid()

' Execute the request. 
Dim response As ImportCompressedXmlWithProgressResponse = CType(service.Execute(request), ImportCompressedXmlWithProgressResponse)

' Retrieve the results of the import.
' Be aware that using AllColumns may adversely affect 
' performance and cause unwanted cascading in subsequent 
' updates.  A best practice is to retrieve the least amount of 
' data required.
Dim job As importjob = CType(service.Retrieve(EntityName.importjob.ToString(), request.ImportJobId, New AllColumns()), importjob)
Dim data As New XmlDocument()
data.LoadXml(job.data)

' See if the result of the first entity was successful.
Dim node As XmlNode = data.SelectSingleNode("importexportxml/entities/entity/@result")
If node.Value <> "success" Then
   success = False
End If

If success Then
   ' Publish the imported customizations.
   Dim publishXmlRequest As New PublishXmlRequest()

   publishXmlRequest.ParameterXml = customizationXML

   ' Execute the publish request.
   service.Execute(publishXmlRequest)
End If

See Also

Concepts

Reference


© 2010 Microsoft Corporation. All rights reserved.


Show:
© 2014 Microsoft