The following code example illustrates how to perform a document search in an object store.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 repositorysearch_ex.CEWS; namespace repositorysearch_ex { /// <summary> /// Repository search, which also includes an example of paging using maxElements. /// </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 // 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"; // Specify the scope of the search ObjectStoreScope objObjectStoreScope = new ObjectStoreScope(); objObjectStoreScope.objectStore = strObjStoreName; // Create RepositorySearch RepositorySearch objRepositorySearch = new RepositorySearch(); objRepositorySearch.repositorySearchMode = RepositorySearchModeType.Rows; objRepositorySearch.repositorySearchModeSpecified = true; objRepositorySearch.SearchScope = objObjectStoreScope; // Search for documents matching this DocumentTitle property value objRepositorySearch.SearchSQL = "SELECT [DocumentTitle],[Id] FROM [Document] WHERE ([DocumentTitle] like '%DemoDoc%') ORDER BY [DocumentTitle]"; Console.WriteLine("Performing an ExecuteSearch, SQL:"); Console.WriteLine(" {0}", objRepositorySearch.SearchSQL); // Invoke the ExecuteSearch operation ObjectSetType objObjectSet = wseService.ExecuteSearch(objRepositorySearch); // Display the Document Titles int hitCount = (objObjectSet.Object == null) ? 0 : objObjectSet.Object.Length; Console.WriteLine("Documents found ({0}):", hitCount); for (int i = 0; i < hitCount; i++) { SingletonString prpDocumentTitle = (SingletonString)objObjectSet.Object[i].Property[0]; SingletonId prpId = (SingletonId)objObjectSet.Object[i].Property[1]; Console.WriteLine(" [{0}]: '{1}'", i, prpDocumentTitle.Value); Console.WriteLine(" [{0}]: '{1}'", i, prpId.Value); } Console.WriteLine("Press Enter to continue"); Console.ReadLine(); // Perform ExecuteSearch again, with maxElements specified objRepositorySearch.maxElements = 3; objRepositorySearch.maxElementsSpecified = true; Console.WriteLine("Performing ExecuteSearch again, maxElements = {0}:", objRepositorySearch.maxElements); objObjectSet = wseService.ExecuteSearch(objRepositorySearch); int index = 0; objObjectSet = null; do { // Set continueFrom on all but first row set if (objObjectSet != null) { objRepositorySearch.continueFrom = ((EndOfPage)objObjectSet.CollectionTerminator).continueFrom; } objObjectSet = wseService.ExecuteSearch(objRepositorySearch); // Display current row set hitCount = (objObjectSet.Object == null) ? 0 : objObjectSet.Object.Length; for (int i = 0; i < hitCount; i++) { SingletonString prpDocumentTitle = (SingletonString)objObjectSet.Object[i].Property[0]; Console.WriteLine(" [{0}]: '{1}'", index++, prpDocumentTitle.Value); } } while (objObjectSet.CollectionTerminator is EndOfPage); Console.WriteLine("Press Enter to end"); Console.ReadLine(); } } }