The following code example demonstrates how to retrieve all of the choice lists (and their choice values) in a given object store. 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 choicelists_ex.CEWS_SOAP; namespace choicelists_ex { class Class1 { static void Main(string[] args) { const string url = "http://localhost:9080/wsi/FNCEWS35SOAP/"; // 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; // Request soap context 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 an ObjectStore object to retrieve ObjectSpecification elemObjectSpecification = new ObjectSpecification(); elemObjectSpecification.classId = "ObjectStore"; // Symbolic name of object store class elemObjectSpecification.objectStore = objectStore; // Object store name // Create an object request for the ObjectStore object ObjectRequestType[] elemObjectRequestTypeArray = new ObjectRequestType[1]; elemObjectRequestTypeArray[0] = new ObjectRequestType(); elemObjectRequestTypeArray[0].SourceSpecification = elemObjectSpecification; elemObjectRequestTypeArray[0].maxElements = -1; elemObjectRequestTypeArray[0].id = "ObjectStore"; // Create a property filter to limit the properties returned from the ObjectStore // object and its object-valued properties to ChoiceLists, ChoiceValues, and Name PropertyFilterType elemPropFilter = new PropertyFilterType(); elemPropFilter.maxRecursion = 10; elemPropFilter.maxElements = -1; elemPropFilter.maxRecursionSpecified = true; // Create filter element array to hold an IncludeProperties specification for 3 properties elemPropFilter.IncludeProperties = new FilterElementType[3]; // Create filter element for ChoiceLists property elemPropFilter.IncludeProperties[0] = new FilterElementType(); elemPropFilter.IncludeProperties[0].Value = "ChoiceLists"; // Create filter element for ChoiceValues property elemPropFilter.IncludeProperties[1] = new FilterElementType(); elemPropFilter.IncludeProperties[1].Value = "ChoiceValues"; // Create filter element for Name property elemPropFilter.IncludeProperties[2] = new FilterElementType(); elemPropFilter.IncludeProperties[2].Value = "Name"; // Add property filter to object request elemObjectRequestTypeArray[0].PropertyFilter = elemPropFilter; // Create an object response for a GetObjects operation ObjectResponseType[] elemObjectResponseTypeArray; try { // Retrieve the ObjectStore object from the server elemObjectResponseTypeArray = wseService.GetObjects(elemObjectRequestTypeArray); } catch (System.Net.WebException ex) { Console.WriteLine("An exception occurred while requesting an object: [" + ex.Message + "]"); return; } // Create an ObjectValue element to hold the properties collection of the retrieved ObjectStore object ObjectValue objObjectStore = null; if (elemObjectResponseTypeArray[0] is SingleObjectResponse) { objObjectStore = ((SingleObjectResponse)elemObjectResponseTypeArray[0]).Object; } // Get the ChoiceLists property of the ObjectStore object EnumOfObject prpChoiceLists = null; foreach (PropertyType prpProperty in objObjectStore.Property) { if (prpProperty.propertyId == "ChoiceLists") { prpChoiceLists = (EnumOfObject)prpProperty; } } // Get each ChoiceList object in the ChoiceLists property collection int numChoiceLists = (prpChoiceLists.Value == null) ? 0 : prpChoiceLists.Value.Length; for (int iLists = 0; iLists < numChoiceLists; iLists++) { // Get the Name property of each ChoiceList object SingletonString prpChoiceListName = null; foreach (PropertyType prpProperty in prpChoiceLists.Value[iLists].Property) { if (prpProperty.propertyId == "Name") { prpChoiceListName = (SingletonString)prpProperty; } } Console.WriteLine("\nChoice list name: " + prpChoiceListName.Value + "\n"); // Get the ChoiceValues property of each ChoiceList object ListOfObject prpChoiceValues = null; foreach (PropertyType prpProperty in prpChoiceLists.Value[iLists].Property) { if (prpProperty.propertyId == "ChoiceValues") { prpChoiceValues = (ListOfObject)prpProperty; } } // Get each Choice object in the ChoiceValues property collection int numChoiceElements = (prpChoiceValues.Value == null) ? 0 : prpChoiceValues.Value.Length; for (int iChValues = 0; iChValues < numChoiceElements; iChValues++) { // Get the Choice object DependentObjectType objChoice = (DependentObjectType)prpChoiceValues.Value[iChValues]; // Get the Name property of the Choice object SingletonString prpChoiceName = null; foreach (PropertyType prpProperty in objChoice.Property) { if (prpProperty.propertyId == "Name") { prpChoiceName = (SingletonString)prpProperty; } } // Print the Name property values of the ChoiceList and Choice objects Console.WriteLine("The number " + (iChValues + 1).ToString() + " element in <" + prpChoiceListName.Value + ">" + " : " + prpChoiceName.Value ); } } Console.WriteLine("Press Enter to end"); Console.ReadLine(); } } }