using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
 
// Import the web service. Visual Studio automatically generates a proxy
// called ContentService.
using ConsoleApplication2.localhost;
 
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            const string database = "Catalog";
 
            string resultCount;
            string resultOverview;
            string resultSummary;
           
            try
            {
                // Create a new web service proxy. This class is generated automatically
                // using "Add Web Reference" in Visual Studio.
                ContentService xmlWebService = new ContentService();
 
                // Since the web service is stateful, a CookieContainer needs to be
                // set.
                xmlWebService.CookieContainer = new CookieContainer();
 
                // Do the search.
                resultCount = xmlWebService.Search(database, "DC", "title=church");
 
                try
                {
                    // Convert result from string to integer.
                    uint count = uint.Parse(resultCount);
                    Console.WriteLine(count.ToString() + " record(s) found");
                    if (count != 0)
                    {
                        // One or more records has been found.
 
                        // Get an overview.
                        resultOverview = xmlWebService.Overview(database, "DC", "Title, Date", 0, count);
                        Console.WriteLine(resultOverview);
 
                        // Get a summary record for the first record
                        resultSummary = xmlWebService.SummaryHeader(database, 0);                                               
                        Console.WriteLine(resultSummary);
                    }
                }
                catch (FormatException)
                {
                    // If the search API returns anything other than an integer, then
                    // this should be treated as an error.
                    Console.WriteLine("Search failed: " + resultCount);
                }
                finally
                {
                    xmlWebService.Abandon();
                }
            }
            catch ( Exception ex )
            {
                Console.WriteLine( "Error: "+ex.Message );
            }
        }
    }
}