Sorry, I've posted a Java code by mistake, this is the right one:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Security.Policy;
namespace ConsoleApplication1
{
class InvokeEncryptDocumentUsingHTTP
{
const int BUFFER_SIZE = 4096;
[STAThread]
static void Main(string[] args)
{
try
{
String urlData =
"http://localhost:8080/WebApplication/Loan.pdf";
//Create an EncryptDocumentServiceWse object and set
authentication values
EncryptDocumentService encryptClient = new
EncryptDocumentService();
encryptClient.Credentials = new
System.Net.NetworkCredential("administrator", "password");
//Create a BLOB object
BLOB inDoc = new BLOB();
//Populate the BLOB objects remoteURL data member
inDoc.remoteURL = urlData;
//Invoke the EncryptDocument process
BLOB outDoc = encryptClient.invoke(inDoc);
//Create a UriBuilder object using the
//BLOB objects 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;
}
}
}
}