API Quick Starts (Code Examples) > Invocation API Quick Starts > Quick Start: Invoking a service using base64 in a Microsoft .NET project

Quick Start: Invoking a service using base64 in a Microsoft .NET project
The following C# code example invokes a process named EncryptDocument from a Microsoft .NET project using Base64 encoding. (See Invoking LiveCycle ES using Base64 Encoding.)
An unsecured PDF document based on a PDF file named map.pdf is passed to the LiveCycle ES process. The process returns a password-encrypted PDF document that is saved as a PDF file named mapEncrypt.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 ES using Base64 Encoding" in 
 * Programming with LiveCycle ES
 */
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.IO;
 
namespace ConsoleApplication1
{
 
    class InvokeEncryptDocumentUsingBase64
    {
 
        const int BUFFER_SIZE = 4096;
        [STAThread]
        static void Main(string[] args)
        {
 
            try
            {
                String pdfFile = "C:\\Adobe\\map.pdf";
                String encryptedPDF = "C:\\Adobe\\mapEncrypt.pdf";
 
                //Create an EncryptDocumentServiceWse object and set authentication values
                EncryptDocumentService encryptClient = new 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);
            }
        }
    }
}

API Quick Starts (Code Examples) > Invocation API Quick Starts > Quick Start: Invoking a service using base64 in a Microsoft .NET project

Programming with LiveCycle ES (LiveDocs)
Adobe LiveCycle ES Update 1

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/livecycle/8.2/programLC/programmer/help/000009.html