Quick Start (MTOM): Assembling multiple XDP fragments using the web service API

The following C# web service code example assembles XDP fragments that are based on the following XDP files: tuc018_template_flowed.xdp, tuc018_contact.xdp, and tuc018_patient.xdp. The assembled XDP document that contains all fragments is saved as a XDP file named AssemblerResultXDP.xdp. (See Assembling Multiple XDP Fragments.)

???/** 
    * Ensure that you create a .NET project that uses  
    * MS Visual Studio 2008 and version 3.5 of the .NET 
    * framework. This is required to invoke a  
    * LiveCycle service using MTOM. 
    *      
    * For information, see "Invoking LiveCycle using MTOM" in Programming with LiveCycle 
    *  
    *  This is the DDX file is used to assemble multiple XDP documents: 
    * <?xml version="1.0" encoding="UTF-8"?> 
    * <DDX xmlns="http://ns.adobe.com/DDX/1.0/"> 
    *    <XDP result="tuc018result.xdp"> 
    *       <XDP source="tuc018_template_flowed.xdp"> 
    *          <XDPContent insertionPoint="ddx_fragment" source="tuc018_contact.xdp" fragment="subPatientContact" required="false"/> 
    *          <XDPContent insertionPoint="ddx_fragment" source="tuc018_patient.xdp" fragment="subPatientPhysical" required="false"/> 
    *          <XDPContent insertionPoint="ddx_fragment" source="tuc018_patient.xdp" fragment="subPatientHealth" required="false"/> 
    *       </XDP> 
    *    </XDP>         
    * </DDX> 
    * 
    */ 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.ServiceModel; 
using System.IO; 
using AssembleXDPDocuments.ServiceReference1; 
 
namespace AssembleXDPDocuments 
{ 
       class Program 
       { 
           static void Main(string[] args) 
           { 
               try 
               { 
                   //Create an AssemblerServiceClient object 
                   AssemblerServiceClient assembleClient = new AssemblerServiceClient(); 
                   assembleClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://hiro-xp:8080/soap/services/AssemblerService?blob=mtom"); 
 
                   //Enable BASIC HTTP authentication 
                   BasicHttpBinding b = (BasicHttpBinding)assembleClient.Endpoint.Binding; 
                   b.MessageEncoding = WSMessageEncoding.Mtom; 
                   assembleClient.ClientCredentials.UserName.UserName = "administrator"; 
                   assembleClient.ClientCredentials.UserName.Password = "password"; 
                   b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; 
                   b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; 
                   b.MaxReceivedMessageSize = 4000000; 
                   b.MaxBufferSize = 4000000; 
                   b.ReaderQuotas.MaxArrayLength = 4000000; 
 
                   // Create BLOBs that represents the input files required to assemble multiple XDP files 
                   BLOB myDDX = new BLOB(); 
                   BLOB inSourceBLOB = new BLOB(); 
                   BLOB inFragment1BLOB = new BLOB(); 
                   BLOB inFragment2BLOB = new BLOB(); 
     
                   // Get the input DDX document and input PDF sources 
                   string ddxFileName = "C:\\Adobe\fragmentDDX.xml"; 
                   FileStream ddxFs = new FileStream(ddxFileName, FileMode.Open); 
 
                   string inSource = "C:\\Adobe\tuc018_template_flowed.xdp"; 
                   FileStream inSourceFileFS = new FileStream(inSource, FileMode.Open); 
 
                   string inFragment1Source = "C:\\Adobe\tuc018_contact.xdp"; 
                   FileStream inFragment1SourceFS = new FileStream(inFragment1Source, FileMode.Open); 
 
                   string inFragment2Source = "C:\\Adobe\tuc018_patient.xdp"; 
                   FileStream inFragment2SourceFS = new FileStream(inFragment2Source, FileMode.Open); 
     
                   // Get the lengths of the file streams and create byte arrays 
                   int ddxLen = (int)ddxFs.Length; 
                   byte[] ddxByteArray = new byte[ddxLen]; 
 
                   int inSourceFileLen = (int)inSourceFileFS.Length; 
                   byte[] inSourceFileByteArray = new byte[inSourceFileLen]; 
 
                   int inFragment1SourceLen = (int)inFragment1SourceFS.Length; 
                   byte[] inFragment1SourceByteArray = new byte[inFragment1SourceLen]; 
 
                   int inFragment2SourceLen = (int)inFragment2SourceFS.Length; 
                   byte[] inFragment2SourceByteArray = new byte[inFragment2SourceLen]; 
     
                   // Populate the byte arrays with the contents of the file streams 
                   ddxFs.Read(ddxByteArray, 0, ddxLen); 
                   inSourceFileFS.Read(inSourceFileByteArray, 0, inSourceFileLen); 
                   inFragment1SourceFS.Read(inFragment1SourceByteArray, 0, inFragment1SourceLen); 
                   inFragment2SourceFS.Read(inFragment2SourceByteArray, 0, inFragment2SourceLen); 
     
                   // Populate the BLOB objects 
                   myDDX.MTOM = ddxByteArray; 
                   inSourceBLOB.MTOM = inSourceFileByteArray; 
                   inFragment1BLOB.MTOM = inFragment1SourceByteArray; 
                   inFragment2BLOB.MTOM = inFragment2SourceByteArray; 
     
                   // Create the map containing the PDF source documents 
                   MyMapOf_xsd_string_To_xsd_anyType inputMap = new MyMapOf_xsd_string_To_xsd_anyType(); 
 
                   MyMapOf_xsd_string_To_xsd_anyType_Item inSourceDoc = new MyMapOf_xsd_string_To_xsd_anyType_Item(); 
                   inSourceDoc.key = "tuc018_template_flowed.xdp"; 
                   inSourceDoc.value = inSourceBLOB; 
 
                   MyMapOf_xsd_string_To_xsd_anyType_Item inFragment1SourceDoc = new MyMapOf_xsd_string_To_xsd_anyType_Item(); 
                   inFragment1SourceDoc.key = "tuc018_contact.xdp"; 
                   inFragment1SourceDoc.value = inFragment1BLOB; 
 
                   MyMapOf_xsd_string_To_xsd_anyType_Item inFragment2SourceDoc = new MyMapOf_xsd_string_To_xsd_anyType_Item(); 
                   inFragment2SourceDoc.key = "tuc018_patient.xdp"; 
                   inFragment2SourceDoc.value = inFragment2BLOB; 
     
                   //Add all elements to the collection 
                   inputMap.Add(inSourceDoc); 
                   inputMap.Add(inFragment1SourceDoc); 
                   inputMap.Add(inFragment2SourceDoc); 
     
                   // Create an AssemblerOptionsSpec object 
                   AssemblerOptionSpec assemblerSpec = new AssemblerOptionSpec(); 
                   assemblerSpec.failOnError = false; 
 
                   // Send the request to the Assembler Service 
                   AssemblerResult result = assembleClient.invoke(myDDX, inputMap, assemblerSpec); 
 
                   // Extract the newly created PDF document from the returned map 
                   BLOB outDoc = null; 
                   AssembleXDPDocuments.ServiceReference1.Map mapResult = result.documents; 
                   for (int i = 0; i < mapResult.Count; i++) 
                   { 
                       String myKey = (String)(mapResult[i].key); 
 
                       if (myKey == "tuc018result.xdp") 
                       { 
                           outDoc = (BLOB)(mapResult[i].value); 
                       } 
                   } 
 
                   //Populate a byte array with the BLOB 
                   byte[] outByteArray = outDoc.MTOM; 
 
                   //Create a new file containing the returned PDF document 
                   string FILE_NAME = "C:\\AssemblerResultXDP.xdp"; 
                   FileStream fs2 = new FileStream(FILE_NAME, FileMode.OpenOrCreate); 
                   BinaryWriter w = new BinaryWriter(fs2); 
                   w.Write(outByteArray); 
                   w.Close(); 
                   fs2.Close(); 
                   Console.WriteLine("The XDP document was created."); 
               } 
 
               catch (Exception ee) 
               { 
                   Console.WriteLine("An unexpected exception was encountered: " + ee.Message + "\n" + ee.StackTrace); 
               } 
           } 
       } 
}