The following code example illustrates how to check out an existing document and check it back in. This example assumes a web reference named CEWS has been set to the following URI: http://localhost:<port>/wsi/FNCEWS40MTOM/wsdl.
using System; using Microsoft.Web.Services3; using Microsoft.Web.Services3.Security.Tokens; using Microsoft.Web.Services3.Design; using documentcheckout_ex.CEWS; namespace documentcheckout_ex { /// <summary> /// Document check out and check in. /// </summary> class Class1 { static void Main(string[] args) { const string strUrl = "http://localhost:9080/wsi/FNCEWS40MTOM/"; // Change port number if necessary const string strObjStoreName = "ContentEngineExs"; // Pre-existing object store const string strDocPath = "/TestFolder/DemoDoc"; // Path to a pre-existing document in object store // Create a wse-enabled web service object FNCEWS40ServiceWse wseService = new FNCEWS40ServiceWse(); // Set security token with your username and password UsernameToken token = new UsernameToken("username", "password", PasswordOption.SendPlainText); wseService.SetClientCredential(token); Policy MyPolicy = new Policy(); MyPolicy.Assertions.Add(new UsernameOverTransportAssertion()); wseService.SetPolicy(MyPolicy); wseService.Url = strUrl; wseService.RequireMtom = true; // Add default locale info to SOAP header Localization objDefaultLocale = new Localization(); objDefaultLocale.Locale = "en-US"; // Build the Checkout action CheckoutAction objCheckout = new CheckoutAction(); objCheckout.reservationType = ReservationType.Exclusive; objCheckout.reservationTypeSpecified = true; // Assign the action to the ChangeRequestType element ChangeRequestType objChangeRequestType = new ChangeRequestType(); objChangeRequestType.Action = new ActionType[1]; objChangeRequestType.Action[0] = (ActionType)objCheckout; // Set a reference to the document to check out ObjectSpecification objDocument = new ObjectSpecification(); objDocument.classId = "Document"; objDocument.path = strDocPath; objDocument.objectStore = strObjStoreName; // Specify the target object (a document) for the actions objChangeRequestType.TargetSpecification = objDocument; objChangeRequestType.id = "1"; // Create a Property Filter to get Reservation property PropertyFilterType objPropFilter = new PropertyFilterType(); objPropFilter.maxRecursion = 1; objPropFilter.maxRecursionSpecified = true; objPropFilter.IncludeProperties = new FilterElementType[1]; objPropFilter.IncludeProperties[0] = new FilterElementType(); objPropFilter.IncludeProperties[0].Value = "Reservation"; // Assign the list of included properties to the ChangeRequestType element objChangeRequestType.RefreshFilter = objPropFilter; // Create array of ChangeRequestType elements and assign ChangeRequestType element to it ChangeRequestType[] objChangeRequestTypeArray = new ChangeRequestType[1]; objChangeRequestTypeArray[0] = objChangeRequestType; // Create ChangeResponseType element array ChangeResponseType[] objChangeResponseTypeArray; // Build ExecuteChangesRequest element and assign ChangeRequestType element array to it ExecuteChangesRequest objExecuteChangesRequest = new ExecuteChangesRequest(); objExecuteChangesRequest.ChangeRequest = objChangeRequestTypeArray; objExecuteChangesRequest.refresh = true; // return a refreshed object objExecuteChangesRequest.refreshSpecified = true; try { // Call ExecuteChanges operation to implement the doc checkout objChangeResponseTypeArray = wseService.ExecuteChanges(objExecuteChangesRequest); } catch(System.Net.WebException ex) { Console.WriteLine("An exception occurred while checking in a document: [" + ex.Message + "]"); return; } // The new document object should be returned, unless there is an error if (objChangeResponseTypeArray == null || objChangeResponseTypeArray.Length < 1) { Console.WriteLine("A valid object was not returned from the ExecuteChanges operation"); return; } // Get Reservation object from Reservation property SingletonObject prpReservation = (SingletonObject) objChangeResponseTypeArray[0].Property[0]; ObjectValue objReservation = (ObjectValue) prpReservation.Value; // Build the Checkin action CheckinAction objCheckin = new CheckinAction(); // Assign the action to the ChangeRequestType element objChangeRequestType.Action = new ActionType[1]; objChangeRequestType.Action[0] = (ActionType)objCheckin; // Specify the target object (Reservation object) for the actions objChangeRequestType.TargetSpecification = new ObjectReference(); objChangeRequestType.TargetSpecification.classId = "Document"; objChangeRequestType.TargetSpecification.objectId = objReservation.objectId; objChangeRequestType.TargetSpecification.objectStore = strObjStoreName; objChangeRequestType.id = "1"; // Assign ChangeRequestType element objChangeRequestTypeArray[0] = objChangeRequestType; // Build ExecuteChangesRequest element and assign ChangeRequestType element array to it objExecuteChangesRequest.ChangeRequest = objChangeRequestTypeArray; objExecuteChangesRequest.refresh = true; // return a refreshed object objExecuteChangesRequest.refreshSpecified = true; try { // Call ExecuteChanges operation to implement the doc checkout objChangeResponseTypeArray = wseService.ExecuteChanges(objExecuteChangesRequest); } catch(System.Net.WebException ex) { Console.WriteLine("An exception occurred while checking out a document: [" + ex.Message + "]"); return; } // The new document object should be returned, unless there is an error if (objChangeResponseTypeArray == null || objChangeResponseTypeArray.Length < 1) { Console.WriteLine("A valid object was not returned from the ExecuteChanges operation"); return; } Console.WriteLine("Checked-in Document '{0}'.", strDocPath); Console.WriteLine("Press Enter to end"); Console.ReadLine(); } } }