Document Checkin Example

The following code example demonstrates how to check in a document reservation. This example assumes a web reference named CEWS_SOAP has been set to the following URI: http://localhost:<port>/wsi/FNCEWS35SOAP/wsdl.

using System;
using Microsoft.Web.Services2;
using Microsoft.Web.Services2.Dime;
using Microsoft.Web.Services2.Security.Tokens;
using documentcheckin_ex.CEWS_SOAP;

namespace documentcheckin_ex
{
   /// <summary>
   /// Check in a document reservation.
   /// </summary>
   class Class1
   {
      /// <summary>
      /// The main entry point for the application
      /// </summary>
      [STAThread]
      static void Main(string[] args)
      {
         //**************************************************************
         // This code example demonstrates how to check in a previously 
         // checked-out document.
         //**************************************************************

         const string url = "http://localhost:9080/wsi/FNCEWS35SOAP/";  // Change port number if necessary
         const string objectStore = "ContentEngineExs";  // Pre-existing object store
         const string documentPath = "/TestFolder/DemoDoc";   // Path to a checked-out document in the object store
         
         // Create a WSE-enabled web service object to provide access to SOAP header
         FNCEWS35ServiceWse wseService = new FNCEWS35ServiceWse();      
         wseService.Url = url;
         SoapContext soapContext = wseService.RequestSoapContext;
         
         // Add security token to SOAP header with your username and password
         UsernameToken token = new UsernameToken("username", "password", PasswordOption.SendPlainText);
         soapContext.Security.Tokens.Add(token);
         
         // Add default locale info to SOAP header
         Localization defaultLocale = new Localization();
         defaultLocale.Locale = "en-US";
         
         // Specify a Document object to retrieve
         ObjectSpecification elemObjectSpecification = new ObjectSpecification();
         elemObjectSpecification.classId = "Document";  // Symbolic name of Document class
         elemObjectSpecification.path = documentPath;  // Path to the document
         elemObjectSpecification.objectStore = objectStore;  // Object store in which the document is located

         // Create a property filter to limit the properties returned from the Document object
         PropertyFilterType elemPropFilter = new PropertyFilterType();
         elemPropFilter.maxRecursion = 1;
         elemPropFilter.maxRecursionSpecified = true;
         
         // Create filter element array to hold an IncludeProperties specification for the Reservation property
         elemPropFilter.IncludeProperties = new FilterElementType[1];
         elemPropFilter.IncludeProperties[0] = new FilterElementType();
         elemPropFilter.IncludeProperties[0].Value = "Reservation";
         
         // Create the request for GetObjects
         ObjectRequestType[] elemObjectRequestTypeArray = new ObjectRequestType[1];
         elemObjectRequestTypeArray[0] = new ObjectRequestType();
         elemObjectRequestTypeArray[0].SourceSpecification = elemObjectSpecification;
         elemObjectRequestTypeArray[0].PropertyFilter = elemPropFilter;

         // Create an object response for a GetObjects operation
         ObjectResponseType[] elemObjectResponseTypeArray;

         try
         {
            // Get the Document object from the server
            elemObjectResponseTypeArray = wseService.GetObjects(elemObjectRequestTypeArray);
         }
         catch(System.Net.WebException ex)
         {
            Console.WriteLine("An exception occurred while requesting a document: [" + ex.Message + "]");
            return;
         }
         
         // Create an ObjectValue element to hold the properties collection of the retrieved Document object         
         ObjectValue objDocument = null;
         if (elemObjectResponseTypeArray[0] is SingleObjectResponse)
         {
            objDocument = ((SingleObjectResponse)elemObjectResponseTypeArray[0]).Object;
         }

         // Get Document's Reservation property
         SingletonObject prpReservation = null;
         foreach (PropertyType prpProperty in objDocument.Property)
         {
            if (prpProperty.propertyId == "Reservation")
            {
               prpReservation = (SingletonObject)prpProperty;
            }
         }
		 
         // Verify that the document reservation exists
         if (prpReservation.Value == null)
         {
            Console.WriteLine("The document is not checked out");
            return;
         }

         // Get Reservation object from the Document's Reservation property
         ObjectValue objReservation = (ObjectValue)prpReservation.Value;
         
         // Build Checkin action
         CheckinAction verbCheckin = new CheckinAction();
         
         // Assign the action to the ChangeRequestType element
         ChangeRequestType[] elemChangeRequestTypeArray = new ChangeRequestType[1];
         ChangeRequestType elemChangeRequestType = new ChangeRequestType();
         elemChangeRequestType.Action = new ActionType[1];
         elemChangeRequestType.Action[0] = (ActionType)verbCheckin;
         elemChangeRequestTypeArray[0] = elemChangeRequestType;
         
         // Create ChangeResponseType element array 
         ChangeResponseType[] elemChangeResponseTypeArray;
   
         // Build ExecuteChangesRequest element
         ExecuteChangesRequest elemExecuteChangesRequest = new ExecuteChangesRequest(); 
         elemExecuteChangesRequest.ChangeRequest = elemChangeRequestTypeArray;
         elemExecuteChangesRequest.refresh = true; // Return a refreshed object
         elemExecuteChangesRequest.refreshSpecified = true;
   
         // Specify the target object (Reservation object) for the actions
         elemChangeRequestType.TargetSpecification = new ObjectReference(); 
         elemChangeRequestType.TargetSpecification.classId = "Document";
         elemChangeRequestType.TargetSpecification.objectId = objReservation.objectId;  
         elemChangeRequestType.TargetSpecification.objectStore = objectStore;
         elemChangeRequestType.id = "1";
         
         // Assign ChangeRequestType element
         elemChangeRequestTypeArray[0] = elemChangeRequestType;
   
         // Build ExecuteChangesRequest element
         elemExecuteChangesRequest.ChangeRequest = elemChangeRequestTypeArray;
         elemExecuteChangesRequest.refresh = true;  // Return a refreshed object
         elemExecuteChangesRequest.refreshSpecified = true;
   
         try
         {
            // Call ExecuteChanges operation to implement the Reservation object
            elemChangeResponseTypeArray = wseService.ExecuteChanges(elemExecuteChangesRequest);
         }
         catch(System.Net.WebException ex)
         {
            Console.WriteLine("An exception occurred while checking in a document: [" + ex.Message + "]");
            return;
         }
		 
         // Return the new Document object, unless there is an error
         if (elemChangeResponseTypeArray == null || elemChangeResponseTypeArray.Length < 1)
         {
            Console.WriteLine("A valid object was not returned from the ExecuteChanges operation");
            return;
         }
         Console.WriteLine("Checked-in Document '{0}'.", documentPath);
      }
   }
}