/// <summary>
        /// Use Enterprise API to create new SFDC records
        /// </summary>
        /// <param name="sessionId"></param>
        /// <param name="serverUrl"></param>
        private static void CreateEnterpriseRecords()
        {
            Console.WriteLine("Creating an account record with the Enterprise API ...");

            //set query endpoint to value returned by login request
            EndpointAddress apiAddr = new EndpointAddress(serverUrl);

            //instantiate session header object and set session id
            enterprise.SessionHeader header = new enterprise.SessionHeader();
            header.sessionId = sessionId;

            //create service client to call API endpoint
            using (enterprise.SoapClient createClient = new enterprise.SoapClient("Soap", apiAddr))
            {
                enterprise.Account newAcct = new enterprise.Account();
                newAcct.Name          = "DevForce02";
                newAcct.AccountNumber = "10043332";
                //all non-string fields must have their corresponding <name>Specified property set
                newAcct.AnnualRevenue = 4000000f;
                //newAcct.AnnualRevenueSpecified = true;

                enterprise.Opportunity o = new enterprise.Opportunity();
                o.Name               = "Opp2";
                o.StageName          = "Prospecting";
                o.CloseDate          = DateTime.Parse("2013-03-22");
                o.CloseDateSpecified = true;

                enterprise.SaveResult[] results;

                createClient.create(
                    header,                         //sessionheader
                    null,                           //assignmentruleheader
                    null,                           //mruheader
                    null,                           //allowfieldtruncationheader
                    null,                           //disablefeedtrackingheader
                    null,                           //streamingenabledheader
                    null,                           //allornoneheader
                    null,                           //debuggingheader
                    null,                           //packageversionheader
                    null,                           //emailheader
                    new enterprise.sObject[] { o }, //objects to add
                    out results                     //results of the creation operation
                    );

                //only added one item, so looking at first index of results object
                if (results[0].success)
                {
                    Console.WriteLine("Account successfully created.");
                }
                else
                {
                    Console.WriteLine(results[0].errors[0].message);
                }

                Console.ReadLine();
            }
        }
        /// <summary>
        /// Use Enterprise API to create new SFDC records
        /// </summary>
        /// <param name="sessionId"></param>
        /// <param name="serverUrl"></param>
        private static void CreateEnterpriseRecords()
        {
             Console.WriteLine("Creating an account record with the Enterprise API ...");

            //set query endpoint to value returned by login request
            EndpointAddress apiAddr = new EndpointAddress(serverUrl);

            //instantiate session header object and set session id
            enterprise.SessionHeader header = new enterprise.SessionHeader();
            header.sessionId = sessionId;

            //create service client to call API endpoint
            using (enterprise.SoapClient createClient = new enterprise.SoapClient("Soap", apiAddr))
            {
                enterprise.Account newAcct = new enterprise.Account();
                newAcct.Name = "DevForce02";
                newAcct.AccountNumber = "10043332";
                //all non-string fields must have their corresponding <name>Specified property set
                newAcct.AnnualRevenue = 4000000f;
                //newAcct.AnnualRevenueSpecified = true;

                enterprise.Opportunity o = new enterprise.Opportunity();
                o.Name = "Opp2";
                o.StageName = "Prospecting";
                o.CloseDate = DateTime.Parse("2013-03-22");
                o.CloseDateSpecified = true;

                enterprise.SaveResult[] results;

                createClient.create(
                    header, //sessionheader
                    null, //assignmentruleheader
                    null, //mruheader
                    null, //allowfieldtruncationheader
                    null, //disablefeedtrackingheader
                    null, //streamingenabledheader
                    null, //allornoneheader
                    null, //debuggingheader
                    null, //packageversionheader
                    null, //emailheader
                    new enterprise.sObject[] { o }, //objects to add
                    out results //results of the creation operation
                    );

                //only added one item, so looking at first index of results object
                if (results[0].success)
                {
                    Console.WriteLine("Account successfully created.");
                }
                else
                {
                    Console.WriteLine(results[0].errors[0].message);
                }

                Console.ReadLine();
            }
        }
        /// <summary>
        /// Use Enteprise API to query and retrieve SFDC records
        /// </summary>
        /// <param name="sessionId"></param>
        /// <param name="serverUrl"></param>
        private static void QueryEnterpriseRecord()
        {
            Console.WriteLine("Querying account records with the Enterprise API ...");

            //set query endpoint to value returned by login request
            EndpointAddress apiAddr = new EndpointAddress(serverUrl);

            //instantiate session header object and set session id
            enterprise.SessionHeader header = new enterprise.SessionHeader();
            header.sessionId = sessionId;

            //create service client to call API endpoint
            using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr))
            {
                //query standard or custom objects

                //create SOQL query statement
                string query = "SELECT Name, AccountNumber, BillingState FROM Account WHERE BillingState = 'CA'";
                
                enterprise.QueryResult result = queryClient.query(
                    header, //sessionheader
                    null, //queryoptions
                    null, //mruheader
                    null, //packageversion
                    query);

                //cast query results
                IEnumerable<enterprise.Account> accountList = result.records.Cast<enterprise.Account>();
                
                //show results
                foreach (var account in accountList)
                {
                    Console.WriteLine(string.Format("Account Name: {0}", account.Name));
                }

                Console.WriteLine("");
                Console.WriteLine("Query complete.");
                Console.ReadLine();

                //retrieve example

                //call retrieve operation to get one or more records of a given type and ID
                enterprise.sObject[] retrievedAccounts = queryClient.retrieve(
                    header, //sessionheader
                    null, //queryoptions
                    null, //mruheader
                    null, //packageversion
                    "Name, BillingState", //fieldlist
                    "Account", //objectype
                    new string[] { "001E000000N1H1O" } //record IDs
                    );

                foreach (enterprise.sObject so in retrievedAccounts)
                {
                    enterprise.Account acct = (enterprise.Account)so;
                    Console.WriteLine(string.Format("Account Name: {0}, Account State: {1}", acct.Name, acct.BillingState));
                }

                Console.WriteLine("");
                Console.WriteLine("Retrieve complete.");
                Console.ReadLine();
            }
        }
        /// <summary>
        /// Use Enteprise API to query and retrieve SFDC records
        /// </summary>
        /// <param name="sessionId"></param>
        /// <param name="serverUrl"></param>
        private static void QueryEnterpriseRecord()
        {
            Console.WriteLine("Querying account records with the Enterprise API ...");

            //set query endpoint to value returned by login request
            EndpointAddress apiAddr = new EndpointAddress(serverUrl);

            //instantiate session header object and set session id
            enterprise.SessionHeader header = new enterprise.SessionHeader();
            header.sessionId = sessionId;

            //create service client to call API endpoint
            using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr))
            {
                //query standard or custom objects

                //create SOQL query statement
                string query = "SELECT Name, AccountNumber, BillingState FROM Account WHERE BillingState = 'CA'";

                enterprise.QueryResult result = queryClient.query(
                    header, //sessionheader
                    null,   //queryoptions
                    null,   //mruheader
                    null,   //packageversion
                    query);

                //cast query results
                IEnumerable <enterprise.Account> accountList = result.records.Cast <enterprise.Account>();

                //show results
                foreach (var account in accountList)
                {
                    Console.WriteLine(string.Format("Account Name: {0}", account.Name));
                }

                Console.WriteLine("");
                Console.WriteLine("Query complete.");
                Console.ReadLine();

                //retrieve example

                //call retrieve operation to get one or more records of a given type and ID
                enterprise.sObject[] retrievedAccounts = queryClient.retrieve(
                    header,               //sessionheader
                    null,                 //queryoptions
                    null,                 //mruheader
                    null,                 //packageversion
                    "Name, BillingState", //fieldlist
                    "Account",            //objectype
                    new string[] { "001E000000N1H1O" } //record IDs
                    );

                foreach (enterprise.sObject so in retrievedAccounts)
                {
                    enterprise.Account acct = (enterprise.Account)so;
                    Console.WriteLine(string.Format("Account Name: {0}, Account State: {1}", acct.Name, acct.BillingState));
                }

                Console.WriteLine("");
                Console.WriteLine("Retrieve complete.");
                Console.ReadLine();
            }
        }