The following code example illustrates how to create a document, add content to it using inline base64 content, and check it in. 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.Security.Tokens; using documentcreateinline_ex.CEWS_SOAP; namespace documentcreateinline_ex { /// <summary> /// Create and check in a document using inline content. /// </summary> class Class1 { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { const string url = "http://localhost:9080/wsi/FNCEWS35SOAP/"; // Change port number if necessary const string contentFile = "c:/test/demo.doc"; // Path to a pre-existing document const string objectStore = "ContentEngineExs"; // Pre-existing object store string documentTitle = "DemoDoc"; // DocumentTitle property value of the new document System.DateTime dateCreated = new System.DateTime(); // 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"; // Build the Create action for a document CreateAction verbCreate = new CreateAction(); verbCreate.classId = "Document"; // Build the Checkin action CheckinAction verbCheckin = new CheckinAction(); verbCheckin.checkinMinorVersion = true; verbCheckin.checkinMinorVersionSpecified = true; // Assign the actions to the ChangeRequestType element ChangeRequestType elemChangeRequestType = new ChangeRequestType(); elemChangeRequestType.Action = new ActionType[2]; elemChangeRequestType.Action[0] = (ActionType)verbCreate; // Assign Create action elemChangeRequestType.Action[1] = (ActionType)verbCheckin; // Assign Checkin action // Specify the target object (an object store) for the actions elemChangeRequestType.TargetSpecification = new ObjectReference(); elemChangeRequestType.TargetSpecification.classId = "ObjectStore"; elemChangeRequestType.TargetSpecification.objectId = objectStore; elemChangeRequestType.id = "1"; // Build a list of properties to set in the new doc ModifiablePropertyType[] elemInputProps = new ModifiablePropertyType[2]; // Specify and set a string-valued property for the DocumentTitle property SingletonString propDocumentTitle = new SingletonString(); propDocumentTitle.Value = documentTitle; propDocumentTitle.propertyId = "DocumentTitle"; elemInputProps[0] = propDocumentTitle; // Add to property list // Create an object reference to dependently persistable ContentTransfer object DependentObjectType objContentTransfer = new DependentObjectType(); objContentTransfer.classId = "ContentTransfer"; objContentTransfer.dependentAction = DependentObjectTypeDependentAction.Insert; objContentTransfer.dependentActionSpecified = true; objContentTransfer.Property = new PropertyType[2]; // Create reference to the object set of ContentTransfer objects returned by the Document.ContentElements property ListOfObject propContentElement = new ListOfObject(); propContentElement.propertyId = "ContentElements"; propContentElement.Value = new DependentObjectType[1]; propContentElement.Value[0] = objContentTransfer; // Read data stream from file containing the document content InlineContent elemInlineContent = new InlineContent(); System.IO.Stream inputStream = System.IO.File.OpenRead(contentFile); elemInlineContent.Binary = new byte[inputStream.Length]; inputStream.Read(elemInlineContent.Binary, 0, (int)inputStream.Length); inputStream.Close(); // Create reference to Content pseudo-property ContentData propContent = new ContentData(); propContent.Value = (ContentType)elemInlineContent; propContent.propertyId = "Content"; // Assign Content property to ContentTransfer object objContentTransfer.Property[0] = propContent; // Create and assign ContentType string-valued property to ContentTransfer object SingletonString propContentType = new SingletonString(); propContentType.propertyId = "ContentType"; propContentType.Value = "application/msword"; // Set MIME-type to MS Word objContentTransfer.Property[1] = propContentType; elemInputProps[1] = propContentElement; // Assign list of document properties to set in ChangeRequestType element elemChangeRequestType.ActionProperties = elemInputProps; // Build a list of properties to exclude on the new doc object that will be returned string[] excludeProps = new string[2]; excludeProps[0] = "Owner"; excludeProps[1] = "DateLastModified"; // Assign the list of excluded properties to the ChangeRequestType element elemChangeRequestType.RefreshFilter = new PropertyFilterType(); elemChangeRequestType.RefreshFilter.ExcludeProperties = excludeProps; // Create array of ChangeRequestType elements and assign ChangeRequestType element to it ChangeRequestType[] elemChangeRequestTypeArray = new ChangeRequestType[1]; elemChangeRequestTypeArray[0] = elemChangeRequestType; // Create ChangeResponseType element array ChangeResponseType[] elemChangeResponseTypeArray = null; // Build ExecuteChangesRequest element and assign ChangeRequestType element array to it ExecuteChangesRequest elemExecuteChangesRequest = new ExecuteChangesRequest(); elemExecuteChangesRequest.ChangeRequest = elemChangeRequestTypeArray; elemExecuteChangesRequest.refresh = true; // return a refreshed object elemExecuteChangesRequest.refreshSpecified = true; try { // Call ExecuteChanges operation to implement the doc creation and checkin elemChangeResponseTypeArray = wseService.ExecuteChanges(elemExecuteChangesRequest); } catch(System.Net.WebException ex) { Console.WriteLine("An exception occurred while creating a document: [" + ex.Message + "]"); return; } // The new document object should be returned, unless there is an error if (elemChangeResponseTypeArray==null || elemChangeResponseTypeArray.Length < 1) { Console.WriteLine("A valid object was not returned from the ExecuteChanges operation"); return; } // Capture value of the DocumentTitle property in the returned doc object foreach (PropertyType propProperty in elemChangeResponseTypeArray[0].Property) { // If property found, store its value if (propProperty.propertyId == "DocumentTitle") { documentTitle = ((SingletonString)propProperty).Value; break; } } // Capture value of the DateCreated property in the returned doc object foreach (PropertyType propProperty in elemChangeResponseTypeArray[0].Property) { // If property found, store its value if (propProperty.propertyId == "DateCreated") { dateCreated = ((SingletonDateTime)propProperty).Value; break; } } Console.WriteLine("The document " + documentTitle + " was successfully created " + dateCreated + "."); } //Main } // class1 }