Quick Start (MTOM): Passing documents to the Output Service using the web service API

The following C# quick start retrieves the file Loan.xdp from Content Services. This XDP file is located in the space / Company Home/Form Designs . The XDP file is returned in a BLOB instance. The BLOB instance is passed to the Output service. The non-interactive form is saved as a PDF file named Loan.pdf on the client computer. Because the File URI option is set, the PDF file Loan.pdf is also saved on the J2EE application server hosting AEM Forms. (See Passing Documents located in Content Services ES2 to the Output Service.)

???/** 
    * 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 AEM forms   
    */ 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.ServiceModel; 
using System.IO; 
 
//A reference to the Output service  
using PassingDocuments.ServiceReference1; 
 
//A reference to the Document Management service  
using PassingDocuments.ServiceReference2; 
 
namespace PassingDocuments 
{ 
       class Program 
       { 
           static void Main(string[] args) 
           { 
               try 
               { 
                   //Because BLOB objects are used in both service references 
                   //it is necessary to fully-qualify the BLOB objects 
 
                   //Retrieve the XDP file from Content Services 
                   PassingDocuments.ServiceReference2.BLOB xdpContent = GetFormDesign(); 
 
                   //Create a BLOB object associated with the Output service 
                   PassingDocuments.ServiceReference1.BLOB formDesign = new PassingDocuments.ServiceReference1.BLOB(); 
 
                   //Transfer the byte stream from one BLOB object to the  
                   //Output BLOB object 
                   formDesign.MTOM = xdpContent.MTOM; 
 
                   //Render the interactive form 
                   RenderNonInteractiveForm(formDesign); 
               } 
               catch (Exception ee) 
               { 
                   Console.WriteLine(ee.Message); 
               } 
           } 
 
           //Get the form design from Content Services - invoke the Document  
           //Management service 
           private static PassingDocuments.ServiceReference2.BLOB GetFormDesign() 
           { 
               try 
               { 
                   //Specify the name of the store and node 
                   String storeName = "SpacesStore"; 
                   String nodeName = "/Company Home/Form Designs/Loan.xdp"; 
 
                   //Create a DocumentManagementServiceClient object 
                   DocumentManagementServiceClient docManagement = new DocumentManagementServiceClient(); 
                   docManagement.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://[server]:[port]/soap/services/DocumentManagementService?blob=mtom"); 
 
                   //Enable BASIC HTTP authentication 
                   BasicHttpBinding b = (BasicHttpBinding)docManagement.Endpoint.Binding; 
                   b.MessageEncoding = WSMessageEncoding.Mtom; 
                   docManagement.ClientCredentials.UserName.UserName = "administrator"; 
                   docManagement.ClientCredentials.UserName.Password = "password"; 
                   b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; 
                   b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; 
                   b.MaxReceivedMessageSize = 2000000; 
                   b.MaxBufferSize = 2000000; 
                   b.ReaderQuotas.MaxArrayLength = 2000000; 
 
                   //Prepare output values 
                   CRCResult content; 
                   String outVal; 
                   PassingDocuments.ServiceReference2.BLOB outDoc; 
                   PassingDocuments.ServiceReference2.MyMapOf_xsd_string_To_xsd_anyType nodeAttributes; 
 
                   //Retrieve /Company Home/Form Designs/Loan.xdp 
                   docManagement.retrieveContent(storeName, 
                       nodeName, 
                       "", 
                       out outVal, 
                       out outDoc, 
                       out nodeAttributes, 
                       out content); 
 
                   return outDoc; 
               } 
               catch (Exception ee) 
               { 
                   Console.WriteLine(ee.Message); 
               } 
 
               return null; 
           } 
 
           //Render the non-interactive form -- invoke the Output service 
           private static void RenderNonInteractiveForm(PassingDocuments.ServiceReference1.BLOB pdfForm) 
           { 
               try 
               { 
                   //Create an OutputServiceClient object 
                   OutputServiceClient outputClient = new OutputServiceClient(); 
                   outputClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://[server]:[port]/soap/services/OutputService?blob=mtom"); 
 
                   //Enable BASIC HTTP authentication 
                   BasicHttpBinding b = (BasicHttpBinding)outputClient.Endpoint.Binding; 
                   b.MessageEncoding = WSMessageEncoding.Mtom; 
                   outputClient.ClientCredentials.UserName.UserName = "administrator"; 
                   outputClient.ClientCredentials.UserName.Password = "password"; 
                   b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; 
                   b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; 
                   b.MaxReceivedMessageSize = 2000000; 
                   b.MaxBufferSize = 2000000; 
                   b.ReaderQuotas.MaxArrayLength = 2000000; 
 
                   //Create a BLOB object to store form data 
                   PassingDocuments.ServiceReference1.BLOB inData = new PassingDocuments.ServiceReference1.BLOB(); 
 
                   //Reference XML data to merge into the PDF document 
                   string inputFileName = "C:\\Adobe\Loan.xml"; 
                   FileStream fs = new FileStream(inputFileName, FileMode.Open); 
 
                   //Get the length of the file stream and create a byte array  
                   int len = (int)fs.Length; 
                   byte[] byteArray = new byte[len]; 
 
                   //Populate the byte array with the contents of the file stream 
                   fs.Read(byteArray, 0, len); 
 
                   //Populate the BLOB object 
                   inData.MTOM = byteArray; 
 
                   //Set PDF run-time options 
                   PDFOutputOptionsSpec pdfOptions = new PDFOutputOptionsSpec(); 
                   pdfOptions.fileURI = "C:\\Adobe\Loan.pdf"; 
 
                   //Set rendering run-time options 
                   RenderOptionsSpec renderOptions = new RenderOptionsSpec(); 
                   renderOptions.cacheEnabled = true; 
                   renderOptions.PDFAConformance = PDFAConformance.A; 
                   renderOptions.PDFARevisionNumber = PDFARevisionNumber.Revision_1; 
                   pdfOptions.lookAhead = 300; 
                   pdfOptions.recordLevel = 1; 
 
                   //Create empty objects to pass as arguments 
                   //to the generatePDFOutput method 
                   //These objects are populated by the method 
                   PassingDocuments.ServiceReference1.BLOB generatePDFOutputMetaDataDoc = new PassingDocuments.ServiceReference1.BLOB(); 
                   PassingDocuments.ServiceReference1.BLOB generatePDFOutputResultDoc = new PassingDocuments.ServiceReference1.BLOB(); 
                   OutputResult outResult = new OutputResult(); 
 
                   //Create a non-interactive document - invoke the generatePDFOutput2 method 
                  outputClient.generatePDFOutput2( 
                           TransformationFormat.PDF, 
                           "C:\\Adobe", 
                           pdfForm, 
                           pdfOptions, 
                           renderOptions, 
                           inData, 
                           out generatePDFOutputMetaDataDoc, 
                           out outResult); 
 
                   //Write the result data to Output.xml 
                   //Populate a byte array with BLOB data 
                   byte[] outByteArray = outResult.generatedDoc.MTOM; 
 
                   //Create a new file to store result data 
                   string FILE_NAME = "C:\\Adobe\Loan.pdf"; 
                   FileStream fs2 = new FileStream(FILE_NAME, FileMode.OpenOrCreate); 
 
                   //Create a BinaryWriter object 
                   BinaryWriter w = new BinaryWriter(fs2); 
                   w.Write(outByteArray); 
                   w.Close(); 
                   fs2.Close(); 
               } 
 
               catch (Exception ee) 
               { 
                   Console.WriteLine(ee.Message); 
               } 
           } 
       } 
} 
 

// Ethnio survey code removed