The following code example illustrates how to perform a document search in an object store. This example assumes a web reference named CEWS_DIME has been set to the following URI: http://localhost:<port>/wsi/FNCEWS35DIME/wsdl.
using System; using Microsoft.Web.Services2; using Microsoft.Web.Services2.Security.Tokens; using repositorysearch_ex.CEWS_DIME; namespace repositorysearch_ex { /// <summary> /// Example repository search, which also includes an example of paging using maxElements. /// </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/FNCEWS35DIME/"; // Change port number if necessary const string objectStore = "ContentEngineExs"; // Pre-existing 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 the scope of the search ObjectStoreScope elemObjectStoreScope = new ObjectStoreScope(); elemObjectStoreScope.objectStore = objectStore; // Create RepositorySearch RepositorySearch elemRepositorySearch = new RepositorySearch(); elemRepositorySearch.repositorySearchMode = RepositorySearchModeType.Rows; elemRepositorySearch.repositorySearchModeSpecified = true; elemRepositorySearch.SearchScope = elemObjectStoreScope; // Search for documents matching this DocumentTitle property value elemRepositorySearch.SearchSQL = "SELECT [DocumentTitle],[Id] FROM [Document] WHERE ([DocumentTitle] like '%DemoDoc%') ORDER BY [DocumentTitle]"; Console.WriteLine("Performing an ExecuteSearch, SQL:"); Console.WriteLine(" {0}", elemRepositorySearch.SearchSQL); // Invoke the ExecuteSearch operation ObjectSetType objObjectSet = wseService.ExecuteSearch(elemRepositorySearch); // 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 propDocumentTitle = (SingletonString)objObjectSet.Object[i].Property[0]; SingletonId propId = (SingletonId)objObjectSet.Object[i].Property[1]; Console.WriteLine(" [{0}]: '{1}'", i, propDocumentTitle.Value); Console.WriteLine(" [{0}]: '{1}'", i, propId.Value); } Console.WriteLine("Press Enter to continue"); Console.ReadLine(); // Perform ExecuteSearch again, with maxElements specified elemRepositorySearch.maxElements = 3; elemRepositorySearch.maxElementsSpecified = true; Console.WriteLine("Performing ExecuteSearch again, maxElements = {0}:", elemRepositorySearch.maxElements); objObjectSet = wseService.ExecuteSearch(elemRepositorySearch); int index = 0; objObjectSet = null; do { // Set continueFrom on all but first row set if (objObjectSet != null) { elemRepositorySearch.continueFrom = ((EndOfPage)objObjectSet.CollectionTerminator).continueFrom; } objObjectSet = wseService.ExecuteSearch(elemRepositorySearch); // Display current row set hitCount = (objObjectSet.Object == null) ? 0 : objObjectSet.Object.Length; for (int i = 0; i < hitCount; i++) { SingletonString propDocumentTitle = (SingletonString)objObjectSet.Object[i].Property[0]; Console.WriteLine(" [{0}]: '{1}'", index++, propDocumentTitle.Value); } } while (objObjectSet.CollectionTerminator is EndOfPage); Console.WriteLine("Press Enter to end"); Console.ReadLine();
} //Main } // class1 }