Quick Start (MTOM): Inspecting policy protected PDF documents using the web service API

The following C# code example inspects a policy-protected PDF document named PolicyProtectedLoanDoc.pdf. (See Inspecting Policy Protected PDF Documents.)

???/** 
    * 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; 
using InspectDocument.ServiceReference1; 
 
namespace InspectDocument 
{ 
       class Program 
       { 
           static void Main(string[] args) 
           { 
               try 
               { 
                   //Create a RightsManagementServiceClient object 
                   RightsManagementServiceClient rmClient = new RightsManagementServiceClient(); 
                   rmClient.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://hiro-xp:8080/soap/services/RightsManagementService?blob=mtom"); 
 
                   //Enable BASIC HTTP authentication 
                   BasicHttpBinding b = (BasicHttpBinding)rmClient.Endpoint.Binding; 
                   b.MessageEncoding = WSMessageEncoding.Mtom; 
                   rmClient.ClientCredentials.UserName.UserName = "administrator"; 
                   rmClient.ClientCredentials.UserName.Password = "password"; 
                   b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic; 
                   b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; 
 
                   //Create a BLOB object to store the PDF document to reinstate  
                   BLOB inDoc = new BLOB(); 
 
                   //Specify the PDF document to inspect 
                   string path = "C:\\Adobe\PolicyProtectedLoanDoc.pdf"; 
                   FileStream fs = new FileStream(path, FileMode.Open); 
 
                   //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.MTOM = ByteArray; 
 
                   //Inspect the policy-protected PDF document 
                   RMInspectResult inspectResult = rmClient.inspectDocument(inDoc); 
 
                   //Get the document name 
                   String documentName = inspectResult.docName; 
     
                   //Get the name of the policy 
                String policyName = inspectResult.policyName; 
                     
                //Display the name of the policy-protected document and the policy 
                Console.WriteLine("The policy protected document "+documentName +" is protected with the policy "+policyName +"."); 
               } 
 
               catch (Exception ee) 
               { 
                   Console.WriteLine(ee.Message); 
               } 
           } 
       } 
}