Quick Start: Invoking a service using BLOB data over HTTP in a .NET project

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

An unsecured PDF document based on a PDF file named Loan.pdf is passed to the LiveCycle process using BLOB over HTTP. 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  
    * SOAP over HTTP. This is required to populate a BLOB  
    * object's remote URL data memeber. 
    *  
    * For information, see "Invoking LiveCycle using BLOB data over HTTP" in  
    * Programming with LiveCycle 
    */ 
using System; 
using System.Collections; 
using System.ComponentModel; 
using System.Data; 
using System.IO; 
using System.Security.Policy; 
 
namespace InvokeEncryptDocumentHTTP 
{ 
 
       class InvokeEncryptDocumentUsingHTTP 
       { 
 
           const int BUFFER_SIZE = 4096; 
           [STAThread] 
           static void Main(string[] args) 
           { 
 
               try 
               { 
                   String urlData = "http://hiro-xp:8080/FormsQS/Loan.pdf"; 
 
                   //Create a MyApplication_EncryptDocumentService object and set authentication values 
                   MyApplication_EncryptDocumentService encryptClient = new MyApplication_EncryptDocumentService(); 
                   encryptClient.Credentials = new System.Net.NetworkCredential("administrator", "password"); 
 
                   //Create a BLOB object 
                   BLOB inDoc = new BLOB(); 
 
                   //Populate the BLOB object's remoteURL data member 
                   inDoc.remoteURL = urlData; 
 
                   //Invoke the EncryptDocument process 
                   BLOB outDoc = encryptClient.invoke(inDoc); 
 
                   //Create a UriBuilder object using the  
                   //BLOB object's remoteURL data member field 
                   UriBuilder uri = new UriBuilder(outDoc.remoteURL); 
 
                  //Convert the UriBuilder to a Stream object 
                   System.Net.WebRequest wr = System.Net.WebRequest.Create(uri.Uri); 
                   System.Net.WebResponse response = wr.GetResponse(); 
                   System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream()); 
                   Stream mySteam = sr.BaseStream; 
 
                   //Create a byte array 
                   byte[] myData = new byte[BUFFER_SIZE]; 
 
                  //Populate the byte array 
                  PopulateArray(mySteam, myData); 
 
                  //Create a new file named UsageRightsLoan.pdf 
                  FileStream fs2 = new FileStream("C:\\Adobe\EncryptedPDF.pdf", FileMode.OpenOrCreate); 
 
                  //Create a BinaryWriter object 
                  BinaryWriter w = new BinaryWriter(fs2); 
                  w.Write(myData); 
                  w.Close(); 
                  fs2.Close(); 
               } 
               catch (Exception ee) 
               { 
                   Console.WriteLine(ee.Message); 
               } 
           } 
 
           public static void PopulateArray(Stream stream, byte[] data) 
           { 
               int offset = 0; 
               int remaining = data.Length; 
               while (remaining > 0) 
               { 
                   int read = stream.Read(data, offset, remaining); 
                   if (read <= 0) 
                       throw new EndOfStreamException(); 
                   remaining -= read; 
                   offset += read; 
               } 
           } 
     
       } 
} 

// Ethnio survey code removed