Quick Start (MTOM): Exporting form data using the web service API

The following C# code example exports data from a PDF form. The form data is saved to an XML file named Loan_data.xml. (See Exporting Form Data.)

/** 
    * 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   
    */ 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.ServiceModel; 
using System.IO; 
 
//A reference to the FormDataIntegration service  
using ExportData.ServiceReference1; 
 
 
namespace ExportData 
{ 
       class Program 
       { 
           static void Main(string[] args) 
           { 
               try 
               { 
                   //Create an OutputServiceClient object 
                   FormDataIntegrationClient dataClient = new FormDataIntegrationClient(); 
                   dataClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://hiro-xp:8080/soap/services/FormDataIntegration?blob=mtom"); 
 
                   //Enable BASIC HTTP authentication 
                   BasicHttpBinding b = (BasicHttpBinding)dataClient.Endpoint.Binding; 
                   b.MessageEncoding = WSMessageEncoding.Mtom; 
                   dataClient.ClientCredentials.UserName.UserName = "administrator"; 
                   dataClient.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 the form from which data is exported  
                   BLOB inForm = new BLOB(); 
 
                   //Reference the form that contains data 
                   string inputFileName2 = "C:\\Adobe\ResultLoanForm.pdf"; 
                   FileStream fs2 = new FileStream(inputFileName2, FileMode.Open); 
 
                   //Get the length of the file stream and create a byte array  
                   int len2 = (int)fs2.Length; 
                   byte[] byteArray2 = new byte[len2]; 
 
                   //Populate the byte array with the contents of the file stream 
                   fs2.Read(byteArray2, 0, len2); 
 
                   //Populate the BLOB object 
                   inForm.MTOM = byteArray2; 
 
                   //Export form data 
                   BLOB outData = dataClient.exportData(inForm); 
 
                   //Write the XML data to a XML file 
                   byte[] outByteArray = outData.MTOM; 
 
                   //Create a new file to store result data 
                   string FILE_NAME = "C:\\Adobe\Loan_data.xml"; 
                   FileStream fs3 = new FileStream(FILE_NAME, FileMode.OpenOrCreate); 
 
                   //Create a BinaryWriter object 
                   BinaryWriter w = new BinaryWriter(fs3); 
                   w.Write(outByteArray); 
                   w.Close(); 
                   fs3.Close(); 
               } 
               catch (Exception ee) 
               { 
                   Console.WriteLine(ee.Message); 
               } 
           } 
       } 
}