Quick Start: Invoking a service using base64 in a Microsoft .NET project

The following C# code example invokes a process named MyApplication/EncryptDocument from a Microsoft .NET project using Base64 encoding. (See Invoking LiveCycle using Base64 encoding.)

An unsecured PDF document based on a PDF file named Loan.pdf is passed to the LiveCycle process. The process returns a password-encrypted PDF document that is saved as a PDF file named EncryptedPDF.pdf.

/* 
    * Ensure that you create a .NET client assembly that uses  
    * base64 encoding. This is required to populate a BLOB  
    * object with data or retrieve data from a BLOB object. 
    *  
    * For information, see "Invoking LiveCycle using Base64 Encoding" in  
    * Programming with LiveCycle 
    */ 
using System; 
using System.Collections; 
using System.ComponentModel; 
using System.Data; 
using System.IO; 
 
namespace InvokeEncryptDocumentBase64 
{ 
 
       class InvokeEncryptDocumentUsingBase64 
       { 
 
           const int BUFFER_SIZE = 4096; 
           [STAThread] 
           static void Main(string[] args) 
           { 
 
               try 
               { 
                   String pdfFile = "C:\\Adobe\Loan.pdf"; 
                   String encryptedPDF = "C:\\Adobe\EncryptedPDF.pdf"; 
 
 
                   //Create an MyApplication_EncryptDocumentService object and set authentication values 
                   MyApplication2_EncryptDocumentService encryptClient = new MyApplication2_EncryptDocumentService(); 
                   encryptClient.Credentials = new System.Net.NetworkCredential("administrator", "password"); 
 
                   //Reference the PDF file to send to the EncryptDocument process 
                   FileStream fs = new FileStream(pdfFile, FileMode.Open); 
     
                   //Create a BLOB object 
                   BLOB inDoc = new BLOB(); 
 
                   //Get the length of the file stream  
                   int len = (int)fs.Length; 
                   byte[] ByteArray = new byte[len]; 
 
                   //Populate the byte array with the contents of the FileStream object 
                   fs.Read(ByteArray, 0, len); 
                   inDoc.binaryData = ByteArray;  
     
                   //Invoke the EncryptDocument process 
                   BLOB outDoc = encryptClient.invoke(inDoc); 
 
                   //Populate a byte array with BLOB data 
                   byte[] outByteArray = outDoc.binaryData; 
 
                   //Create a new file named UsageRightsLoan.pdf 
                   FileStream fs2 = new FileStream(encryptedPDF, 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); 
               } 
           } 
       } 
}